第三周作业
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@t1 ~]# cut -d: -f1 /etc/passwd;grep -v /nologin /etc/passwd|wc -l
2、查出用户UID最大值的用户名、UID及shell类型
[root@t1 ~]# sort -n -t: -k3 /etc/passwd | tail -1 |cut -d: -f1,3,7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@t1 ~]# netstat -tunal | tr -s ' ' | cut -d' ' -f5|grep [0-9]|cut -d: -f1 | sort -n | uniq -c
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash df -h| grep `df -h | tr -s ' ' | cut -d' ' -f5 | grep [0-9] | sort -nr| head -2 `
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#!/bin/bash echo "主机名:"$(hostname) echo -n "IPV4地址: " for i in $(ip add s | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/"); do echo -n ${i///}" ";done echo echo "操作系统版本:"$(cat /etc/redhat-release) echo "内核版本:"$(uname -r) echo "CPU型号:"$(lscpu | grep "Model name" | cut -d: -f2 |tr -s ' ') echo "内存大小:"$(free -h | grep "Mem:"| tr -s ' ' | cut -d' ' -f2) echo -n "硬盘大小:" for i in $(lsblk | grep '^sd' | tr -s ' '| cut -d' ' -f1,4); do echo -n ${i///}" ";done echo
浙公网安备 33010602011771号