1.编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
#!/bin/bash
#
[ $# -eq 0 ] && echo "Usage:./`basename $0` USERNAME1" && exit 10
id $1 &> /dev/null && echo "User $1 is existed,·id $1·" && exit 20
useradd $1 &> /dev/null && echo -e "$1 is created successfully.\n·id $1·" && echo $1 | passwd --stdin $1 &> /dev/null && passwd $1 -x && echo "Created password successed,The same with your Username." && exit 0 || echo "abnormal error.";exit 30
2.编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
7 autocmd BufNewFile *.sh exec ":call SetTitle()"
8
9 func SetTitle()
10 if expand("%:e")=='sh'
11 call setline(1,"#!/bin/bash")
12 call setline(2,"#")
13 call setline(3,"#*************************************")
14 call setline(4,"#author: zhaihuitao")
15 call setline(5,"#QQ: 393905515")
16 call setline(6,"#email: 393905515@qq.com")
17 call setline(7,"#version: 1.0")
18 call setline(8,"#date: ".strftime("%Y-%m-%d"))
19 call setline(9,"#description: test ")
20 call setline(10,"#*************************************")
21
22 endif
23
24 endfunc
3.查找/etc目录下大于1M且类型为普通文件的所有文件
find /etc -type f -size +1M
4.打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份
find /etc/ -name "*.conf" | xargs tar -cpvf `date +%F`.tar && cp -a `date +%F`.tar /usr/local/src/
5.查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
find / \( -nouser -o -nogroup \) -atime -7
6.查找/etc目录下至少有一类用户没有执行权限的文件
find /etc ! -perm -111