AIX系统资源监控SHELL脚本


#!/usr/bin/ksh
PATH=/usr/bin:/bin:/usr/sbin
export PATH
time=$(date +%F)
rq=$(perl -e "use POSIX qw(strftime); print strftime '%F' , localtime( time()-3600*24*7) ")  


cd /tmp/monitor
#内存监控
vmstat 3 20     >       vm_cpu_cal.txt
cat vm_cpu_cal.txt | awk -F ' '  '{print $4}' | grep -v fre | grep -v faults | grep -v -  | grep -v mem | sed -e '/^$/d'        >>      vm_mnr_$time.txt
date                                                                                                                            >>      vm_cal_$time.txt
cat vm_mnr_$time.txt | awk '{sum+=$1} END {print "Average = ", 22912-sum/NR/1024*4}'                                            >>      vm_cal_$time.txt
cat vm_mnr_$time.txt | awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Min=",22912-max/1024*4}'                        >>      vm_cal_$time.txt
cat vm_mnr_$time.txt | awk 'BEGIN {min = 9999999} {if ($1>      cpu_cal_$time.txt
cat cpu_mnr_$time.txt | awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Min=", 100-max,"%"}'                           >>      cpu_cal_$time.txt
cat cpu_mnr_$time.txt | awk 'BEGIN {min = 9999999} {if ($1>      cpu_cal_$time.txt


#清理7天以前历史数据
if [ -f *$rq*.txt ]
then
cd /tmp/monitor/
rm /tmp/monitor/*$rq*
fi

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28371090/viewspace-1780699/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28371090/viewspace-1780699/

你可能感兴趣的:(AIX系统资源监控SHELL脚本)