shell脚本监控

监控磁盘空间

vim check_disk.sh

#!/bin/bash
# test common. #warn=$
#err=$
#mount=$ check_val()
{
/usr/bin/expr $ + > /dev/null >&
return=$(echo $?) if [[ ${return} -ne ]]
then
echo "please input number."
exit
fi
} conf="./check_disk.conf" if [[ ! -f ${conf} ]]
then
echo "config file is not exists."
exit
fi while read line
do
mount=${line%%=*}
monitor=${line##*=}
warn=${monitor%%,*}
err=${monitor##*,} check_val $warn
check_val $err #echo "mount: ${mount}; warrn: ${warrn}; err: ${err}" #qu ci pan kong jian.
value=$(df -h | awk '{if($NF == "'"$line"'") print substr($5,1,length($5)-1)}') if [[ $value -gt ${warn} ]]
then
echo "${mount}: disk is full."
d=$(date +"%s")
cp /root/shell/log/messages /root/shell/log-bak/messages.${d}
cat /dev/null > /root/shell/log/messages
elif [[ $value -gt ${err} ]]
then
echo "${mount}: disk is crital."
else
echo "${mount}: It's normal."
fi
done<${conf}

vim check_disk.conf

/=,
/boot=,
/dev=,90
#此文件里的项目可自定义增减
上一篇:Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件


下一篇:垃圾分类的API