N51期第四次作業

1、統計出/etc/passwd文件中其默認shell爲非/sbin/nologin的用戶個數,並將用戶都顯示出來

[root@centos8mini ~]# cat /etc/passwd | grep -v '/sbin/nologin' | cut -d : -f 1
root
sync
shutdown
halt
xyj

2、查出用戶UID最大值的用戶名、UID及shell類型

[root@centos8mini ~]# cat /etc/passwd | cut -d : -f 1,3,7 | sort -t : -k 2 -n -r | head -1
nobody:65534:/sbin/nologin

3、統計當前連接本機的每個遠程主機IP的連接數,並按從大到小排序

[root@centos8mini ~]# ss -nt | tail -n +2 | tr -s ' ' : | cut -d : -f 6 | sort | uniq -c | sort -n -r

4、編寫腳本disk.sh,顯示當前硬盤分區中空間利用率最大的值

[root@centos8mini scripts]# cat disk.sh 
#!/bin/bash
echo -e "\e[1;31m`df -hT | grep -Eo '([0-9]{1,2}|100)%' | sort -n -r | tr -d % | head -1`\e[0m"

5、編寫腳本 systeminfo.sh,顯示當前主機系統信息,包括:主機名,IPv4地址,操作系統版本,內核版本,CPU型號,內存大小,硬盤大小

#!/bin/bash
echo -e "\e[1;32m**********************主機系統信息**********************\e[0m"
echo -e "\e[1;35m主機名:       `hostname`\e[0m"
echo -e "\e[1;35mIPv4地址:     `ifconfig ens33 | grep -Eo '(([0-9]|[1-9][0-9]|1[0-9]{,2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{,2}|2[0-4][0-9]|25[0-5])' | head -1`\e[0m"
echo -e "\e[1;35m操作系統版本: `cat /etc/redhat-release`\e[0m"
echo -e "\e[1;35m內核版本:     `uname -r`\e[0m"
echo -e "\e[1;35mCPU型號:     `lscpu | grep 'Model name' | tr -s ' ' | cut -d : -f 2`\e[0m"
echo -e "\e[1;35m內存大小:     $(free -h | tr -s ' ' : | cut -d : -f 2 | tail -n $(echo "`free -h | wc -l`-1" | bc) | head -1)\e[0m"
echo -e "\e[1;35m硬盤大小:     `lsblk | grep sda | head -1 | tr -s ' ' : | cut -d : -f 5`\e[0m"
echo -e "\e[1;32m********************************************************\e[0m"

6、20分鐘內通關vimtutor(可參考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章