1、統(tǒng)計出/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶個數(shù),并將用戶都顯示出來
雙河ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作![root@centos7 ~]# grep -v "/sbin/nologin" /etc/passwd |wc -l && grep -v "/sbin/nologin" /etc/passwd |cut -d ":" -f1
15
root
sync
shutdown
halt
rick
gentoo
docker
mongodb
redis
tomcat
nginx
ric
mageia
slackware
test
[root@centos7 ~]#
2、查出用戶UID大值的用戶名、UID及shell類型
方法一:
[root@centos7 ~]# cat /etc/passwd |sort -t: -k3 -nr |head -1 |cut -d: -f1,3,7
方法二:
[root@centos7 ~]# cat max_uid.sh
#!/bin/bash
uid=`cat /etc/passwd |cut -d ":" -f3`
for i in $uid
do
??????? max=0
??????? if [ $i -gt $max ]
??????? then
??????????????? max=$i
??????? fi
done
grep $max /etc/passwd |cut -d ":" -f1,3,7
[root@centos7 ~]# sh max_uid.sh?????
test:2003:/bin/bash
[root@centos7 ~]# tail -3 /etc/passwd
mageia:x:1100:1100::/homenux:/bin/bash
slackware:x:2002:2019::/home/slackware:/bin/tcsh
test:x:2003:2003::/home/test:/bin/bash
[root@centos7 ~]#
3、統(tǒng)計當(dāng)前連接本機(jī)的每個遠(yuǎn)程主機(jī)IP的連接數(shù),并按從大到小排序
[root@centos7 ~]#ss -tnla |grep ESTAB |tr -s " " |cut -d " " -f5 |sort |uniq -c |sort -nr |head
??? 119 127.0.0.1:3306
???? 40 ::ffff:127.0.0.1:3306
???? 21 ::ffff:59.39.91.244:3306
????? 4 ::ffff:127.0.0.1:60009
????? 2 127.0.0.1:55555
????? 1 ::ffff:61.146.78.146:64634
????? 1 ::ffff:61.143.130.174:30895
????? 1 ::ffff:59.39.91.244:58830
????? 1 ::ffff:59.39.91.244:58818
????? 1 ::ffff:59.39.91.244:58263
4、編寫腳本?createuser.sh,實現(xiàn)如下功能:使用一個用戶名做為參數(shù),如果?指定參數(shù)的用戶存在,就顯示其存在,否則添加之;顯示添加的用戶的id號等?信息
[root@centos7 ~]# cat createuser.sh
#!/bin/bash
#********************************************************************
#Author:??????????????? rickzhu
#QQ:??????????????????? 1779526363
#Date:????????????????? 2020-02-28
#FileName:???????????? createuser.sh
#URL:?????????????????? http://www.magedu.com
#Description:????????? The test script
#Copyright (C):???????? 2020 All rights reserved
#********************************************************************
if grep $1 /etc/passwd >/dev/null
then
??????? echo "$1 is exist."
else
??????? useradd $1
??????? echo "`id $1`"
fi
[root@centos7 ~]# sh createuser.sh nginx
nginx is exist.
[root@centos7 ~]# sh createuser.sh test
uid=2003(test) gid=2003(test) groups=2003(test)
[root@centos7 ~]#
5、編寫生成腳本基本格式的腳本,包括作者,聯(lián)系方式,版本,時間,描述等
[root@centos7 ~]# cat createScript.sh
#!/bin/bash
#
#判斷當(dāng)前目錄是否有同名的腳本
if ls |grep $1 >>/dev/null
then
??????? echo "$1 is exist" && exit 10
fi
?
cat <<EOF > $1 && vim + $1
#!/bin/bash
#
#********************************************************************
#Author:??????????????? rickzhu
#QQ:??????????????????? 1779526363
#Date:????????????????? `date +%F`
#FileName:???????????? $1
#Version??????????????? 1
#URL:?????????????????? http://www.magedu.com
#Description:????????? The $1 script
#Copyright (C):???????? 2020 All rights reserved
#********************************************************************
EOF
[root@centos7 ~]#
[root@centos7 ~]# sh createScript.sh test.sh
#!/bin/bash
#
#********************************************************************
#Author:??????????????? rickzhu
#QQ:??????????????????? 1779526363
#Date:????????????????? 2020-02-28
#FileName:???????????? test.sh
#Version??????????????? 1??????????????
#URL:?????????????????? http://www.magedu.com
#Description:????????? The test.sh script
#Copyright (C):???????? 2020 All rights reserved
#********************************************************************???????????????????????????????????????????????
~? ? ?
當(dāng)前標(biāo)題:centos7之文本處理及shell基礎(chǔ)編程-創(chuàng)新互聯(lián)
鏈接地址:http://m.rwnh.cn/article0/ddooio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站導(dǎo)航、App設(shè)計、定制開發(fā)、品牌網(wǎng)站制作、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容