[root@centos7 script]#vim createuser.sh #!/bin/bash##********************************************************************#Author: iamalu#QQ: 2425942026#Date: 2020-04-03#FileName: createuser.sh#URL: http://www.iamalu.com#Description: The test script#Copyright (C): 2020 All rights reserved#********************************************************************[$# -eq 0]&&{echo"Usage:`basename $0` USERNAME";exit10;}id$1&>/dev/null &&{echo"user $1 is exist!";exit20;}useradd$1&>/dev/null &&{echo"user $1 is created";echo123456|passwd --stdin $1&>/dev/null;}||{echo"error!";exit30;}[root@centos7 script]#bash createuser.sh alice
user alice is created
[root@centos7 script]#bash createuser.sh root
user root is exist![root@centos7 script]#bash createuser.sh
Usage:createuser.sh USERNAME
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@centos7 ~]#vim ~/.vimrcset ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec":call SetTitle()"
func SetTitle()if expand("%:e")=='sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#********************************************************************")
call setline(4,"#Author: iamalu")
call setline(5,"#QQ: 2425942026")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.iamalu.com")
call setline(9,"#Description: The test script")
call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#********************************************************************")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G
1、查找/etc目录下大于1M且类型为普通文件的所有文件
[root@centos7 ~]#find /etc \( -size +1M -a -type f \) -ls15566018144 -r--r--r-- 1 root root 8339001 Mar 17 00:28 /etc/udev/hwdb.bin
2029182881384 -rw-r--r-- 1 root root 1415647 Mar 17 00:23 /etc/selinux/targeted/contexts/files/file_contexts.bin
1351234573784 -rw-r--r-- 1 root root 3874070 Mar 17 00:23 /etc/selinux/targeted/policy/policy.31
703216853784 -rw------- 1 root root 3874070 Mar 17 00:23 /etc/selinux/targeted/active/policy.kern
703216913784 -rw------- 1 root root 3874070 Mar 17 00:23 /etc/selinux/targeted/active/policy.linked
2023968231336 -rw-r--r-- 1 root root 1367395 Apr 112018 /etc/brltty/zh-tw.ctb
[root@centos7 scripts]# vim for_scanip.sh#!/bin/bashNETID=192.168.0.
forHOSTIDin{1..254};do{if /bin/ping -c1 -W1 $NETID$HOSTID>/dev/null ;thenecho"$NETID$HOSTID is success!"elseecho"$NETID$HOSTID is fail!"fi}&donewait[root@centos7 scripts]# bash for_scanip.sh 192.168.0.1 is fail!192.168.0.3 is fail!192.168.0.6 is fail!192.168.0.7 is fail!192.168.0.2 is fail!.....
192.168.0.248 is fail!192.168.0.241 is fail!192.168.0.200 is fail![root@centos7 scripts]# echo 192.168.0.{1..254} |tr -s " " "\n" > ip.txt[root@centos7 scripts]# vim while_scanip.sh#!/bin/bashwhilereadip;do{
/bin/ping -c1 -W1 $ip>/dev/null
if[$? -eq "0"];thenecho"$ip is success!"elseecho"$ip is fail!"fi}&done</data/scripts/ip.txt
wait[root@centos7 scripts]# bash while_scanip.sh 192.168.0.1 is fail!192.168.0.4 is fail!192.168.0.5 is fail!192.168.0.7 is fail!.....
192.168.0.248 is fail!192.168.0.200 is fail!