第四周作业—N42-虚怀若谷
阅读原文时间:2023年07月10日阅读:2

[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

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

[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

[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

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

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章