1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数 ,并将用户都显示出来
[root@C76 ~]# cat /etc/passwd |grep -v ‘sbin/nologin’ |awk -F’:’ ‘{print $1}’ #显示用户
[root@C76 ~]# cat /etc/passwd |grep -v ‘sbin/nologin’|wc -l #显示用户个数
2、查看用户UID最大的用户名、UID及shell类型
[root@C76 ~]# cat /etc/passwd |sort -t: -k3 -nr |awk -F’:’ ‘{print $1,$3,$7}’|head -1
3、统计当前连接本机的每个远程主机的IP的连接数,并 按照从大到小排序
[root@C76 ~]# netstat -tun|grep “ESTABLISHED” |awk -F’ +|:’ ‘{print $6}’|sort -nr |uniq -c
4、编写脚本createuser.sh,实现如下功能:使用一个用户名作为参数,如果指定参数的用户名存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
脚本
[root@C76 ~]# cat createuser.sh
#!/bin/bash
read -p “create a username:” user
id KaTeX parse error: Expected 'EOF', got '&' at position 6: user &̲> /dev/null && …user is exist" && exit 1
useradd
u
s
e
r
>
/
d
e
v
/
n
u
l
l
e
c
h
o
"
user >/dev/null echo "
user>/dev/nullecho"user" |passwd --stdin KaTeX parse error: Expected 'EOF', got '&' at position 17: …ser >/dev/null &̲& echo "user is create and the passwd is username"&& id $user
测试结果
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@C76 ~]# cat ~/.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: liubo")
call setline(5,"#QQ: 1163426929")
call setline(6,"#email: liubo99@163.com")
call setline(7,"#version: 1.0")
call setline(8,"#date: “.strftime(”%Y-%m-%d"))
call setline(9,"#description: the test script")
call setline(10,"#")
endif
endfunc
测试结果
vim ll.sh