1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos7 ~]# getent passwd |grep -c -v "/sbin/nologin"
7
[root@centos7 ~]# getent passwd |grep -v "/sbin/nologin"|cut -d : -f1
root
sync
shutdown
halt
mzy
mageia
slackware
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 ~]# getent passwd |sort -t: -k3 -nr|head -n1 |cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7 ~]# netstat -nt|tr -s " " :|cut -d : -f6|egrep -o "(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"|uniq -c|sort -nr
1 192.168.58.1
4、编写脚本 "createuser.sh",实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
[root@centos7 ~]# cat createuser.sh
set -e
set -u
read -p "please input your username:" USER
if id $USER &> /dev/null;then
echo -e "\e[1;33m This user was created \e[0m"
elif useradd $USER;then
cat /etc/passwd |grep "$USER"
else
echo -e "\e[1;31m EORROR \e[0m"
fi
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@centos7 ~]#vim .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: mazhiyuan")
call setline(5,"#QQ: 1209543044")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileNameZ ".expand("%"))
call setline(8,"#URL: https://blog.51cto.com/13931555")
call setline(9,"#DescriptionZ 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
网友评论