第五周

一、编写脚本 createuser.sh,实现如下功能:

使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

[root@CentOS8 scripts]#NAME=root; id $NAME &> /dev/null && echo "$NAME is exist" || ( useradd $NAME;id $NAME )
root is exist
[root@CentOS8 scripts]#NAME=oracle; id $NAME &> /dev/null && echo "$NAME is exist" || ( useradd $NAME;id $NAME )
uid=1002(oracle) gid=1002(oracle) groups=1002(oracle)


二、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

[root@CentOS8 ~]#vi vimrc.txt 
set 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:              liusir")
        call setline(5,"#QQ:                  1607401544")
        call setline(6,"#Date:                ".strftime("%Y-%m-%d"))
        call setline(7,"#FileName:            ".expand("%"))
        call setline(8,"#URL:                 )
        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
 
[root@CentOS8 ~]#vi vimrc.sh
#!/bin/bash
cat ~/vimrc.txt > ~/.vimrc
 
[root@CentOS8 ~]#bash vimrc.sh
 
[root@CentOS8 ~]#vi text.sh
#!/bin/bash
# 
#***************************************************************
#Author:              liusir
#QQ:                  1607401544
#Date:                2021-04-12
#FileName:            text.sh
#URL:                 
#Description:         The test script
#Copyright (C):       2021 All rights reserved
#***************************************************************


三、查找/etc目录下大于1M且类型为普通文件的所有文件

[root@CentOS8 ~]#find /etc -type f -size +1M
/etc/selinux/targeted/policy/policy.31
/etc/udev/hwdb.bin


四、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。

[root@CentOS8 ~]#find /etc/ -name "*.conf" |xargs tar -zcvf `date +%F`.tar.gz &> /dev/null;cp -a *.tar.gz /usr/local/src/


五、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

[root@CentOS8 ~]#find / -nouser -o -nogroup -a -atime -7


六、查找/etc目录下至少有一类用户没有执行权限的文件

[root@CentOS8 ~]#find /etc -type f ! -perm /111


请使用浏览器的分享功能分享到微信等