您的位置:首页 > 其它

N51期第四次作业

2020-12-20 23:42 1481 查看

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)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: