1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@localhost data]# grep /sbin/nologin /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
......此处省略部分内容
以上命令行将各用户信息也显示出来,可以用cut命令进行调整
[root@localhost data]# grep /sbin/nologin /etc/passwd | cut -d: -f1
bin
daemon
adm
lp
......此处省略部分内容
2、查出用户UID最大值的用户名、UID及shell类型
[root@localhost data]# sort -t: -k3 -nr /etc/passwd | head -1 | cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@localhost data]# netstat -nt | tr -s " " : | cut -d: -f4 | sort |uniq -c | head -1
3 192.168.27.134
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
[root@localhost script]# vim creatuser.sh #打开creatuser.sh,编写脚本
#! /bin/bash
#
read -p "input user: " user
if id $user &>/dev/null ;then
echo "$user is exist,the info is `id $user`"
else
useradd $user && echo "useradd is successful,and the info is `id $user` "
fi
~ # 脚本代码如上,:wq保存退出
[root@localhost script]# bash creatuser.sh #执行脚本
input user: wufujie
wufujie is exist,the info is uid=1000(wufujie) gid=1000(wufujie) groups=1000(wufujie)
[root@localhost script]# bash creatuser.sh
input user: wfj1
useradd is successful,and the info is uid=2005(wfj1) gid=2005(wfj1) groups=2005(wfj1)
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@localhost ~]# ls -a #查看是否已创建.vimrc文件
. anaconda-ks.cfg .bash_logout .bashrc .config .dbus mytest1 .viminfo
.. .bash_history .bash_profile .cache .cshrc initial-setup-ks.cfg .tcshrc .Xauthority
[root@localhost ~]# vim .vimrc #创建并打开.vimrc文件
[root@localhost ~]# cat .vimrc #在.vimrc文件中输入以下信息并保存
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
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: WFJ")
call setline(5,"#QQ: 3495867")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.baidu.com")
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@localhost ~]# vim fi.sh #打开任意.sh文件发现已经配置OK
#!/bin/bash
#
#********************************************************************
#Author: WFJ
#QQ: 3495867
#Date: 2019-12-22
#FileName: fi.sh
#URL: http://www.baidu.com
#Description: The test script
#Copyright (C): 2019 All rights reserved
#********************************************************************
Type :quit<Enter> to exit Vim
网友评论