1、运行时间
[[email protected] ~]# uptime | sed -n ‘/,/s/,/ /gp‘| awk ‘{ > if($4 =="days" || $4 == "day") > {print $2,$3,$4,$5} > else > {print $2,$3}}‘ up 22:54
2、磁盘使用情况
[[email protected] ~]# df -h 文件系统 容量 已用 可用 已用%% 挂载点 /dev/sda2 50G 40G 6.9G 86% / tmpfs 462M 0 462M 0% /dev/shm /dev/sda1 120M 62M 50M 56% /boot /dev/sda5 400G 60G 320G 16% /data0 [[email protected] ~]# df -h /dev/sda2 | sed -n ‘/% \//p‘|awk ‘{print $5}‘ 86%
3、内存使用情况
要以%显示,就乘以100,然后用awk的整数函数int,来清理这个百分比,最后用sed加上一个百分号
[[email protected] ~]# free | sed -n ‘2p‘| awk ‘x=(($3 / $2)*100) {print x}‘|sed ‘s/$/%/‘ 81.0682%
4、僵尸进程
linux系统上僵尸是指处于未知状态的进程。这些进程已经完成了它的工作,但因为种种原因还处于未完成状态,僵尸进程既没有死掉,也没有运行。如果有一两个僵尸进程在Linux上不是什么大问题,但多了,就带来麻烦了。
[[email protected] qingyun]# ps -al | awk ‘{print $2,$4}‘ | grep Z
5、结合起来脚本
[[email protected] tmp]# vim script5 # echo -e "Today is - `date +%m%d%Y`" echo # ########################################################## #1) Gather System Uptime Statistics # echo -e "System has been \c" uptime | sed ‘/,/s/,/ /gp‘|awk ‘{if($4 == "days" || $4 == "day" ){print $2,$3,$4,$5} else {print $2,$3}}‘ # ############################################################ #2)Gather Disk Usage Statistics # echo for DISK in $DISKS_TO_MONITOR #loop to check disk space do echo -e "$DISK usage:\c" df -h $DISK | sed -n ‘/% \//p‘|awk ‘{print $5}‘ done # ############################################################# #3)Gather Memory Usage Statistics # echo echo -e "Memory Usage:\c" # free |sed -n ‘2p‘| awk ‘x = init (($3 / $2)*100){print x}‘| sed ‘s/$/%/‘ # ############################################################# #4)Gather Number of Zomble processes # echo ZOMBLE_CHECK=`ps -al | awk ‘{print $2,$4}‘|grep z` # if [ "$ZOMBLE_CHECK" == "" ] then echo "No Zombie Process on System at this time" else echo "Current System Zombie Processes" ps -al | awk ‘{print $2,$4}‘|grep z fi echo ##############################################################
时间: 2024-10-05 05:21:41