Shell脚本如下:
#/bin/bash #environment variable source /etc/profile #cpu cpu_us=`vmstat | awk '{print $13}' | sed -n '$p'` cpu_sy=`vmstat | awk '{print $14}' | sed -n '$p'` cpu_id=`vmstat | awk '{print $15}' | sed -n '$p'` cpu_sum=$(($cpu_us+$cpu_sy)) if(($cpu_sum >= 90)) then msg="TIME:$(date +%F_%T) HOSTNAME:$(hostname) IPADDR:$(ifconfig |awk 'NR==2{print $2}') MSG:cpu使用率过高!已经用了${cpu_sum}%" echo $msg vmstat | awk '{print $1,$13,$14,$15}' | sed -n '2,$p' > /test/tt.txt /test/sendmail.py $msg fi