1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
echo "用户个数:`cat /etc/passwd | grep "/sbin/nologin" | wc -l`"
echo "用户:`cat /etc/passwd | grep "/sbin/nologin"| awk -F ':' '{print $1}'|tr '\n' ' ' `"
2、查出用户UID最大值的用户名、UID及shell类型
用户名:cat /etc/passwd | sort -k 3 -t : -n | tail -1 | cut -d: -f1
UID:cat /etc/passwd | sort -k 3 -t : -n | tail -1 | cut -d: -f3
shell:cat /etc/passwd | sort -k 3 -t : -n | tail -1 | cut -d: -f7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
netstat -nt | tail -n +3 | awk '{print $5}' | cut -d: -f1 | grep -v "^$" | sort -n | uniq -c| sort -nr
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
cat >disk.sh <<EOF
#! /bin/bash
#
#
echo "max_rate_name=`df | tr -s ' ' | tail -n +2 | sort -k 5 -nr | head -1 |cut -d" " -f1`"
echo "max_rate=`df | tr -s ' ' | tail -n +2 | sort -k 5 -nr | head -1 |cut -d" " -f5`"
EOF
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#! /bin/bash
#显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#
RED="\E[1;31m"
GREEN="echo -e \E[1;32md"
END="\E[0m"
$GREEN----------------------Host systeminfo--------------------$END
echo -e "${RED}HOSTNAME: `hostname`${END}"
echo -e "${RED}IPADDR: `ifconfig ens33 | grep -Eo \"([0-9]{1,3}\.){3}[0-9]{1,3}\" | head -1`${END}"
echo -e "${RED}OSVERSION: `cat /etc/redhat-release`${END}"
echo -e "${RED}KERNEL: `uname -r`${END}"
echo -e "${RED}CPU: `lscpu | grep "Model " | tr -s " " | cut -d: -f2`${END}"
echo -e "${RED}MEMORY: `free -h | tr -s ' '|head -2|tail -1|cut -d' ' -f2`${END}"
echo -e "${RED}DISK: `lsblk |grep "^sd" | tr -s ' ' | cut -d' ' -f4`${END}"
EOF