首页 > 其他 > 详细

第五周

时间:2021-03-13 09:02:37      阅读:29      评论:0      收藏:0      [点我收藏+]

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

[root@localhost ~]# bash   createuser.sh 
daichanshu
[root@localhost ~]# bash   createuser.sh wang
user wang add ok user wang information:uid=1000(wang) gid=1000(wang) groups=1000(wang) 
[root@localhost ~]# cat createuser.sh 
#!/bin/bash
if [ $1 ]; then 
    id $1 &> /dev/null && echo "user $1 exist" || echo "`useradd $1`user $1 add ok user $1 information:$(id $1) "
else
    echo "daichanshu"
fi

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

[root@localhost ~]# cat .vimrc 
set ts=4
set expandtab
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:		none") 
	call setline(5,"#QQ: 			none") 
	call setline(6,"#Date: 			".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		".expand("%"))
	call setline(8,"#URL: 			none")
	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@localhost ~]# 

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

[root@localhost ~]# find /etc/ -size +1M | xargs ls -lh
-rw-r--r--. 1 root root 8.1M Nov 13  2019 /etc/selinux/targeted/policy/policy.31
-r--r--r--. 1 root root 8.8M Feb 21 19:02 /etc/udev/hwdb.bin

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

[root@localhost ~]# 
[root@localhost ~]# tar  -zcvf /usr/local/src/etc_conf_bak`date +%F:%H:%M`.tar.gz $(find /etc/ -name "*.conf" |  tr "\n" " ")

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

[root@localhost ~]# find / \( -nouser -o -nogroup \) -a -atime +6 
find: ‘/proc/3293/task/3293/fd/9’: No such file or directory
find: ‘/proc/3293/task/3293/fdinfo/9’: No such file or directory
find: ‘/proc/3293/fd/5’: No such file or directory
find: ‘/proc/3293/fdinfo/5’: No such file or directory

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

[root@localhost ~]# find /etc/ -not -perm /111

第五周

原文:https://www.cnblogs.com/catastrophe/p/14527214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!