一、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

[root@centos7 ~]# grep -v "/sbin/nologin" /etc/passwd|cut -d: -f1
root
sync
shutdown
halt
hovin
[root@centos7 ~]# grep -v "/sbin/nologin" /etc/passwd|cut -d: -f1|wc -l

二、查出用户UID最大值的用户名、UID及shell类型

[root@centos7 ~]# cut -d : -f ,, /etc/passwd|sort -t : -k  -nr|head -n
nfsnobody::/sbin/nologin

三、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

[root@centos7 ~]# w -h    #查询连接数
root pts/ 192.168.214.1 : .00s .12s .00s w -h
root pts/ 192.168.214.1 : : .03s .00s less -s
root pts/ 172.16.236.130 : : .02s .02s -bash
[root@centos7 ~]# w -h|tr -s " " #压缩空格方便进一步处理
root pts/ 192.168.214.1 : .00s .12s .00s w -h
root pts/ 192.168.214.1 : : .02s .02s -bash
root pts/ 172.16.236.130 : : .02s .02s -bash
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f #取出IP地址
192.168.214.1
192.168.214.1
172.16.236.130
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort #排序
192.168.214.1
192.168.214.1
172.16.236.130
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort|uniq -c #去重并计数
172.16.236.130
192.168.214.1
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort|uniq -c|sort -nr #按计数逆序
192.168.214.1
172.16.236.130

四、编写脚本createuser.sh,实现如下功能:使用一个用户名作为参数,如果指定参数的用户存在,就显示其存在,否则就添加之;显示添加的用户的id号等信息

[root@centos7 scripts]# cat createuser.sh
#!/bin/bash #read -p "please input a username: " USER
USER=$ if [ -z "$USER" ];then
echo "Usage: `basename $0` username"
exit
fi if id $USER &> /dev/null ;then
echo "user: $USER already exists"
exit
else
useradd $USER
echo "user: $USER create success"
id $USER
fi
[root@centos7 scripts]# bash createuser.sh
Usage: createuser.sh username
[root@centos7 scripts]# bash createuser.sh hovin
user: hovin already exists
[root@centos7 scripts]# bash createuser.sh alice
user: alice create success
uid=(alice) gid=(alice) groups=(alice)

五、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

  在.vimrc中定义,对创建的以.sh结尾的脚本应用,相关代码如下:

[root@centos7 ~]# cat .vimrc
set tabstop=
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == sh
call setline(,"#/bin/bash")
call setline(,"#")
call setline(,"#***************************************************")
call setline(,"Author: hovin")
call setline(,"QQ: 405001597")
call setline(,"Date: ".strftime("%Y-%m-%d"))
call setline(,"FileName: ".expand("%"))
call setline(,"Description: The test script")
call setline(,"Copyright (C): ".strftime("%Y")." ALL rights reserved)
call setline(,"#**************************************************")
call setline(,"")
endif
endfunc
autocmd BufNewFile * normal G

[root@centos7 ~]# vim test.sh   #创建脚本

#/bin/bash

#

#***************************************************

Author:             hovin

QQ:                 405001597

Date:               2019-11-23

FileName:           test.sh

Description:        The test script

Copyright (C):      2019 ALL rights reserved

#**************************************************

最新文章

  1. Python的数据类型
  2. SQL Server中的锁 详解 nolock,rowlock,tablock,xlock,paglock
  3. 项目管理-Kick OFF 简称KO
  4. asp.net LINQ连接数据库SQL执行数据的增加、修改、删除、查询操作
  5. OpenCV 第一课(安装与配置)
  6. [转]SVN客户端解决authorization failed问题
  7. Html - 对话箭头
  8. 【Android测试】【随笔】模拟长按电源键
  9. 在Linux命令行下令人惊叹的惊叹号(!)
  10. 将客户端将IE9强制为IE7
  11. 【转】SQL Server 2008下载 (附注册码)
  12. Maps
  13. jquery mobile validation
  14. WSGI是一种编程接口,而uwsgi是一种传输协议
  15. oschina Web应用开发
  16. 快速排序 partition函数的所有版本比较
  17. 在Linux下安装Oracle12c
  18. Docker for windows on VMware
  19. 洛谷P1776--宝物筛选(单调队列+多重背包)
  20. C++雾中风景12:聊聊C++中的Mutex,以及拯救生产力的Boost

热门文章

  1. Python 笔试集:什么时候 i = i + 1 并不等于 i += 1?
  2. 《图解设计模式》读书笔记9-2 Proxy模式
  3. 微服务架构spring cloud - gateway网关限流
  4. GMSSL中生成SM2或RSA1024或RSA2048的证书相关命令
  5. PYTHON2.7之前需要独立安装pip
  6. Cassandra commands
  7. 多线程03-Abort
  8. Git-第三篇廖雪峰Git教程学习笔记(2)回退修改,恢复文件
  9. ES6扩展运算符(三点符号), 解构
  10. [2019杭电多校第三场][hdu6606]Distribution of books(线段树&&dp)