1、统计出/etc/passwd文件中其默认shel为非/s bin/nologin的用户个数,并将用户都显示出来
[root@localhost data]# grep -v /sbin/nologin /etc/passwd|cut -d: -f1 rootsyncshutdown halt dingchao mageia user1 user2 user3 [root@localhost data]# grep -v /sbin/nologin /etc/passwd|cut -d: -f1|wc -l9
2、查出用户UID最大值的用户名、UID及shell类型
[root@localhost data]# cut -d: -f3 /etc/passwd|sort -nr 2005 2004 2003 2002 1100 1000 999 192 99 89 81 74 48 38 14 12 11 8 7 6 5 4 3 2 1 0 [root@localhost data]# grep 2005 /etc/passwd |cut -d: -f1,3,7 user3:2005:/bin/bash
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@localhost data]# ss -nt|tail -n+2|tr -s " " : |cut -d: -f6|uniq -c|sort -rn 2 192.168.1.44 1 192.168.1.4
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@localhost ~]# sh disk.sh \#!/bin/bash \#Description: \#Author:root \#Version:1.0 \#CreateTime:2021-04-02 08:51:10 df -h |tr -s " " :|sort -rn -k 5 -t :|grep -Eo -m 1 [0-9]*% [root@localhost ~]# chmod +x disk.sh [root@localhost ~]# ./disk.sh 18%
5、编写脚本systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址, 操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#!/bin/bash #Description: #Author:root #Version:1.0 #CreateTime:2021-04-02 09:50:42 hostname=" `hostname` " #hostname address=`ifconfig eth0 | sed -n '2p' | grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}'|head -1` #network address systemversion=" `cat /etc/redhat-release` " #system version kernelversion=`uname -r` #kernel version cputype=`grep -E "model name" /proc/cpuinfo |cut -d: -f2` #cpu version mermory=`free -mh|tail -2|tr -s " " :|cut -d: -f2|head -1` #mermory harddisk=`fdisk -l | grep Disk|head -1` #hard disk echo "hostname is $hostname" echo "network address is $address" echo "system version is $systemversion" echo "kernel version is $kernelversion" echo "cpu type is $cputype" echo "mermory is $mermory" echo "hard disk is $harddisk" [root@dingchao ~]# ./systeminfo1.sh hostname is dingchao network address is 192.168.1.48 system version is CentOS Linux release 7.7.1908 (Core) kernel version is 5.4.106-1.el7.elrepo.x86_64 cpu type is Intel(R) Xeon(R) Silver 4210R CPU @ 2.40GHz mermory is 1.9G hard disk is Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors