1.统计出/etc/passwd文件中默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[20:14:48 root@CentOS7 ~]#cat /etc/passwd |grep -v "/sbin/nologin$" |cut -d: -f1
2.查询用户UID最大值的用户名,uid及shell类型
[20:34:59 root@CentOS7 ~]#sort -t: -n -k3 /etc/passwd|tail -1|cut -d: -f1,3,7
3.统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[20:52:35 root@CentOS7 ~]#netstat -t|grep [0-9]|tr -s " " :|cut -d: -f6|uniq -c|sort -nr
4.编写脚本createuser.sh 实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加。显示添加的用户的ID号等信息
#!/bin/bash
COLORB="\033[1;36m"
COLORE="\033[0m"
read -p "please input a username:" USERNAME
id $USERNAME &> /dev/null
if [[ $? -eq 0 ]]; then
echo "the user is exist"
else
useradd $USERNAME
echo tww |passwd --stdin $USERNAME > /dev/null
echo -e "The user is created ,The user's password is:$COLORB tww $COLORE"
echo -e "The information of user's id is:$COLORB `id $USERNAME` $COLORE"
fi
显示结果如下:
5.编写生成脚本基本格式的脚本,包括:作者,联系方式,版本,时间,描述等
将以下代码写入家目录的.vimrc文件中
即:vim /boot/.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: tww")
call setline(5,"#QQ: 123456789")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: https://blog.51cto.com/14814545")
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
显示结果如下: