1、统计出/etc/passwd文件中其默认shell为非"/sbin/nologin"的用户个数,并打印所有匹配到的用户的用户名
#统计个数
awk -F: '!/\/sbin\/nologin$/{print $1}' /etc/passwd
#打印用户名
awk -F: '!/\/sbin\/nologin$/{print $1}' /etc/passwd |wc -l
2、打印用户UID值最大的用户的用户名、UID、shell类型
sort -t ":" -k3 -n /etc/passwd | tail -1 |awk -F: '{print "%s %s %s\n",$3,$5,$7}'
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
w h |awk -F" " '{print $3}' |uniq -c |sort -t " " -k2 -n -r
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
#Author:Jorna
#Date:2020-03-02
#Description:show the top value of used disk space size
topused=`df -lh |grep "^/dev/\S\+" |awk '{print $5}' |sort -r |head -1`
printf "%-10s:%-10s\n" "TopUsed" "$topused"
4、编写脚本systeminfo.sh,显示当前主机系统信息
#!/bin/bash
#Author:Jorna
#Date:2020-03-02
#Description:show system infomation
hostname=`hostname`
kernel=`uname -r`
os_release=`cat /etc/redhat-release`
ipv4=`ip address show ens33 |grep -o -E "([0-9]+.){4}[0-9]+" |head -1`
cpu=`cat /proc/cpuinfo |grep "model name" |uniq |cut -d: -f2| sed 's@^[[:blank:]]*@@g'`
mem=`cat /proc/meminfo |grep "MemTotal" | egrep -o "[0-9]+"`
disksize=`fdisk -l | egrep -o "^Disk.*GB" |egrep -o "[0-9]+.[0-9]+"`
echo "------------------- system infomation ---------------------" && echo
printf "%-30s:%-50s\n" "hostname" "$hostname"
printf "%-30s:%-50s\n" "Linux Kernel Version" "$kernel"
printf "%-30s:%-50s\n" "Linux Release Version" "$os_release"
printf "%-30s:%-50s\n" "IPV4 Address" "$ipv4"
printf "%-30s:%-50s\n" "CPU" "$cpu"
printf "%-30s:%-50s\n" "MEM" "$mem KB"
printf "%-30s:%-50s\n" "DiskSize" "$disksize GB"
echo && echo "-----------------------------------------------------------"