2020-12-27 第五周

1.编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

[20:20:56  root@centos8 scripts]#cat createuser.sh 
#!/bin/bash
read -p "请输入用户的名称: " name
id $name &> /dev/null 
if [ $? = 0 ];then
    echo "此用户已经存在,请从新输入"
else
    useradd $name > /dev/null && id  $name
fi

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

[20:58:55  root@centos8 scripts]#cat ~/.vimrc 
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:                                  zhaofan")
    call setline(5,"#QQ:                                      1826209004")
    call setline(6,"#Date:                               ".strftime("%Y-%m-%d"))
    call setline(7,"#Filename:                                ".expand("%"))
    call setline(8,"#URL:                                     https://www.jianshu.com/u/41fbc4e38dff")
    call setline(9,"#Description:                             The test script")
    call setline(10,"#**************************************************")
    call setline(11,"")
    endif
endfunc
autocmd BufNewFile * normal G

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

[21:03:49  root@centos8 ~]#find /etc -type f -a -size +1M -ls 
   674880   8932 -r--r--r--   1  root     root      9143418 Nov 24 18:27 /etc/udev/hwdb.bin
 33969126   8236 -rw-r--r--   1  root     root      8430018 Nov 13  2019 /etc/selinux/targeted/policy/policy.31
[21:06:45  root@centos8 ~]#find /etc -type f -a -size +1M -exec ls -lh {} \;
-r--r--r--. 1 root root 8.8M Nov 24 18:27 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 8.1M Nov 13  2019 /etc/selinux/targeted/policy/policy.31

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

[21:26:55  root@centos8 ~]#tar -zcvf /usr/local/src/etc_`date +%F`_backup.tar.gz /etc/*.conf
[21:27:00  root@centos8 ~]#ls /usr/local/src/
etc_2020-12-27_backup.tar.gz  httpd-2.4.46  httpd-2.4.46.tar.gz

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

[21:40:56  root@centos8 ~]#find / \( -nouser -nogroup -atime -7 \) -a \( -type f -o -type d \) -exec ls -ldh {} \;
find: ‘/proc/2533’: No such file or directory
find: ‘/proc/2619/task/2619/fdinfo/8’: No such file or directory
find: ‘/proc/2619/fdinfo/7’: No such file or directory
drwx------ 2 2006 2006 62 Dec 27 20:01 /home/zhaofan
-rw-r--r-- 1 2006 2006 18 Nov  9  2019 /home/zhaofan/.bash_logout
-rw-r--r-- 1 2006 2006 141 Nov  9  2019 /home/zhaofan/.bash_profile
-rw-r--r-- 1 2006 2006 312 Nov  9  2019 /home/zhaofan/.bashrc
drwx------ 2 2007 2007 62 Dec 27 20:09 /home/zhaofan1
-rw-r--r-- 1 2007 2007 18 Nov  9  2019 /home/zhaofan1/.bash_logout
-rw-r--r-- 1 2007 2007 141 Nov  9  2019 /home/zhaofan1/.bash_profile
-rw-r--r-- 1 2007 2007 312 Nov  9  2019 /home/zhaofan1/.bashrc

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

[22:12:08  root@centos8 ~]#find /etc/ -perm /111 -type f -exec ls -lh {} \;
-rwxr-xr-x. 1 root root 1016 May 11  2019 /etc/security/namespace.init
-rwxr-xr-x. 1 root root 189 Jan  4  2018 /etc/cron.daily/logrotate
-rwxr-xr-x. 1 root root 575 Nov  9  2019 /etc/cron.hourly/0anacron
-rwxr-xr-x. 1 root root 203 Jun 22  2018 /etc/X11/xinit/xinitrc.d/50-systemd-user.sh
-rwxr-xr-x. 1 root root 1.1K Nov 19  2019 /etc/NetworkManager/dispatcher.d/11-dhclient
-rwxr-xr-x. 1 root root 1.6K Nov  9  2019 /etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
-rwxr-xr-x. 1 root root 8.8K Nov 26  2019 /etc/grub.d/00_header
-rwxr-xr-x. 1 root root 1.3K Nov 26  2019 /etc/grub.d/01_menu_auto_hide
-rwxr-xr-x. 1 root root 232 Nov 26  2019 /etc/grub.d/01_users
-rwxr-xr-x. 1 root root 14K Nov 26  2019 /etc/grub.d/10_linux
-rwxr-xr-x. 1 root root 12K Nov 26  2019 /etc/grub.d/20_linux_xen
-rwxr-xr-x. 1 root root 2.5K Nov 26  2019 /etc/grub.d/20_ppc_terminfo
-rwxr-xr-x. 1 root root 11K Nov 26  2019 /etc/grub.d/30_os-prober
-rwxr-xr-x. 1 root root 1.4K Nov 26  2019 /etc/grub.d/30_uefi-firmware
-rwxr-xr-x. 1 root root 214 Nov 26  2019 /etc/grub.d/40_custom
-rwxr-xr-x. 1 root root 216 Nov 26  2019 /etc/grub.d/41_custom
-rwxr-xr-x. 1 root root 1.1K Jun 27  2019 /etc/grub.d/00_tuned
-rwxr-xr-x. 1 root root 4.3K Nov  9  2019 /etc/vmware-tools/poweroff-vm-default
-rwxr-xr-x. 1 root root 4.3K Nov  9  2019 /etc/vmware-tools/poweron-vm-default
-rwxr-xr-x. 1 root root 4.3K Nov  9  2019 /etc/vmware-tools/resume-vm-default
-rwxr-xr-x. 1 root root 15K Feb 20  2019 /etc/vmware-tools/scripts/vmware/network
-rwxr-xr-x. 1 root root 1.5K Feb 20  2019 /etc/vmware-tools/statechange.subr
-rwxr-xr-x. 1 root root 4.3K Nov  9  2019 /etc/vmware-tools/suspend-vm-default

你可能感兴趣的:(2020-12-27 第五周)