用shell寫一個簡單的告警系統
阿新 • • 發佈:2018-03-17
shell用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 ‘s@ @@g‘` /bin/bash ../shares/502.sh fi
用shell寫一個簡單的告警系統