文章目录
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来2、查出用户UID最大值的用户名、UID及shell类型3、统计当前连接本机的每个远程主机IP的连接数,并按照从大到小排序4、编写脚本createuser.sh, 实现如下功能: 使用一个用户名作为参数,如果指定参数的用户存在,就显示其存在,否则添加之,显示添加的用户的id号等信息5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@lqc ~
]
root
sync
shutdown
halt
laiqiancheng
mageia
slackware
[root@lqc ~
]
[root@lqc ~
]
7
[root@lqc ~
]
用sed命令
[root@lqc ~
]
root
sync
shutdown
halt
laiqiancheng
mageia
slackware
[root@lqc ~
]
7
[root@lqc ~
]
2、查出用户UID最大值的用户名、UID及shell类型
[root@lqc ~
]
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@lqc ~
]
[root@lqc ~
]
nfsnobody:65534:/sbin/nologin
[root@lqc ~
]
[root@lqc ~
]
65534:nfsnobody:/sbin/nologin
[root@lqc ~
]
3、统计当前连接本机的每个远程主机IP的连接数,并按照从大到小排序
sed取出IP排序
[root@lqc ~
]
Active Internet connections
(w/o servers
)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 10.0.0.104:22 10.0.0.1:56425 ESTABLISHED
tcp 0 36 10.0.0.104:22 10.0.0.1:60795 ESTABLISHED
[root@lqc ~
]
10.0.0.1
10.0.0.1
[root@lqc ~
]
2 10.0.0.1
[root@lqc ~
]
grep、tr、cut、取出IP排序
[root@lqc ~
]
Active Internet connections
(w/o servers
)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 10.0.0.104:22 10.0.0.1:56425 ESTABLISHED
tcp 0 36 10.0.0.104:22 10.0.0.1:60795 ESTABLISHED
[root@lqc ~
]
10.0.0.1
10.0.0.1
[root@lqc ~
]
2 10.0.0.1
[root@lqc ~
]
4、编写脚本createuser.sh, 实现如下功能: 使用一个用户名作为参数,如果指定参数的用户存在,就显示其存在,否则添加之,显示添加的用户的id号等信息
[root@lqc scripts
]
set -ue
USER
="$1"
id ${USER} &> /dev/null
&& echo "${USER} is already exsit !" && exit 1
useradd ${USER} && echo "${USER} create success !"
id ${USER} && exit 2
[root@lqc scripts
]
lai is already exsit
!
[root@lqc scripts
]
wang create success
!
uid
=2006
(wang
) gid
=2006
(wang
) groups
=2006
(wang
)
[root@lqc scripts
]
slackware:x:2002:2019::/home/slackware:/bin/tcsh
lai:x:2003:2003::/home/lai:/bin/bash
mage:x:2004:2004::/home/mage:/bin/bash
mage1:x:2005:2005::/home/mage1:/bin/bash
wang:x:2006:2006::/home/wang:/bin/bash
[root@lqc scripts
]
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@lqc scripts
]
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: LaiQianCheng")
call setline
(5,
"#QQ: 2428589167")
call setline
(6,
"#Date: ".strftime
("%Y-%m-%d"))
call setline
(7,
"#FileName: ".expand
("%"))
call setline
(8,
"#URL: https://blog.csdn.net/weixin_45144524")
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@lqc scripts
]