用shell写一个简单的告警系统
- 创建目录结构
mkdir -p /usr/local/sbin/mon/{bin,conf,shares,mail,log}
mon //主目录
bin //主程序目录
shares //子程序目录
mail //发邮件目录
log //日志目录
程序主入口文件/mon/bin/main.sh
#!/bin/bash
export send=1
export addr=`/usr/sbin/ifconfig | grep -A1 ‘ens33‘|awk ‘/inet/{print $2}‘`
dir=`pwd`
last_dir=`echo $dir|awk -F‘/‘ ‘{print $NF}‘`
if [ $last_dir == "bin" ] || [ $last_dir == "bin/" ]; then
conf_file="../conf/mon.conf"
else
echo "you should cd bin dir."
exit
fi
#exec 1>>../log/mon.log 2>>../log/err.log
echo "`date +‘%F %T‘` load average"
/bin/bash ../shares/load.sh
if grep -q ‘to_mon_502=1‘ $conf_file; then
export log=`grep ‘logfile=‘ $conf_file | awk -F ‘=‘ ‘{print $2}‘ | sed ‘[email protected] @@g‘`
/bin/bash ../shares/502.sh
fi
原文地址:http://blog.51cto.com/13480443/2087938
时间: 2024-10-08 06:01:01