1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos7 ~]#grep -v '/sbin/nologin' /etc/passwd |cut -d: -f1
root
sync
shutdown
halt
andy
mageia
slackware
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 ~]#sort -n -k3 -t':' /etc/passwd |tail -1|cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7 ~]#netstat -t|grep [0-9]|tr -s " " :|cut -d: -f4|uniq -c|sort -nr
1 192.168.13.128
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
[root@centos7 ~]#touch createuser.sh
[root@centos7 ~]#vim createuser.sh
#!/bin/bash
#定义变量
_user=`grep -wq ^$1 /etc/passwd;echo $?`
#判断是否有输入参数
if [ $# -eq 0 ];then
echo "你没有输入参数,语法:$0 username"
exit 10
#判断参数指定的用户是否存在
elif [ "$_user" -eq 0 ];then
echo "用户存在,脚本退出"
exit 20
else
echo "用户不存在,将会创建用户$1,并显示用户信息"
useradd $1 && id $1
fi
[root@centos7 ~]#bash createuser.sh
你没有输入参数,语法:createuser.sh username
[root@centos7 ~]#bash createuser.sh any
用户不存在,将会创建用户any,并显示用户信息
uid=2003(any) gid=2003(any) groups=2003(any)
[root@centos7 ~]#bash createuser.sh any
用户存在,脚本退出
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@centos7 ~]# vim ~/.vimrc
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: xuweiran")
call setline(5,"#QQ: ")
call setline(6,"#email: @qq.com")
call setline(7,"#version: 1.0")
call setline(8,"#date: ".strftime("%Y-%m-%d"))
call setline(9,"#description: Keep Going!")
call setline(10,"#*************************************")
endif
endfunc