作业:监控内存,cpu和硬盘的根目录,超过80%提示用户,写成函数库的行,每天早上 的8.50分,执行一次脚本。
[root@test3 opt]# vim zuoye.sh #函数库yingpan () {YP=$(df -h | awk 'NR==2{print $5}')if [[ $YP > 80 ]]thenecho "硬盘占用率超过80%:$YP "elseecho "硬盘正常:$YP "fi
}CPUU () {CPPU=$(top -bn 1 | awk 'NR==3{print}' | awk -F, '{print ($2+$3)*10}')if [[ $CPPU -gt 80 ]]thenecho "cpu占用率超过80%:$CPPU% "elseecho "cpu正常:$CPPU% "fi}neicun () {neicun1=$(free -m | awk 'NR==2{print}' | awk '{print$3/$2*100}')if [[ $neicun -gt 80 ]]thenecho "内存占用率超过80%:$neicun1% "elseecho "内存正常:$neicun1% "fi
}
vim zuoyehanshudiaoyong. /opt/zuoye.shYPAN=`yingpan $YP`
echo "$YPAN"CCPU=`CPUU $CPPU`
echo "$CCPU"NNCC=`neicun $neicun1`
echo "$NNCC"
[root@test3 opt]# crontab -l #每天八点五十执行
50 8 * * * sh /opt/zuoyediaoyong.sh