1. 程式人生 > >監控域名+發送郵件

監控域名+發送郵件

span -s min ret http bsp pan 指定 time

#!/bin/bash
# source ~/.bash_profile
##  curl -m 8 -s -o /dev/null --retry-max-time 8 -w %{http_code}  $url
check_httpd (){
status_code=$(curl -m 20 -s -o /dev/null -w %{http_code} $url)
}
##定義時間變量
date=$(date +%Y/%m/%d-%H:%M:%S)
##把前一個的循環置空,並輸入當前時間
## echo "0當前時間:$date" > /usr/local/zhicbo/000.txt
echo "0當前時間:$date
" > /usr/local/zhicbo/302.txt echo "0當前時間:$date" > /usr/local/zhicbo/error.txt #做循環 for url in `cat /usr/local/zhicbo/yuming.txt` do { check_httpd #指定測試服務器狀態的函數,並根據返回碼決定是發送郵件報警還是將正常信息寫入日誌 if [ $status_code -eq 200 ] || [ $status_code -eq 301 ];then continue elif [ $status_code
-eq 302 ];then echo $url >> /usr/local/zhicbo/302.txt elif [ $status_code -eq 000 ];then echo $url >> /usr/local/zhicbo/000.txt else # [ $status_code -ne 200 ] || [ $status_code -ne 301 ] || [ $status_code -ne 302 ] || [ $status_code -ne 000 ];then echo $url域名異常,狀態碼為$status_code
>> error.txt fi }& #done < /sh/yuming.txt done sleep 10 wait echo "success" ##給導入的文件排序 ## sort -n /usr/local/zhicbo/000.txt -o /usr/local/zhicbo/000.txt sort -n /usr/local/zhicbo/302.txt -o /usr/local/zhicbo/302.txt && sort -n /usr/local/zhicbo/error.txt -o /usr/local/zhicbo/error.txt status_000=`wc -l /usr/local/zhicbo/000.txt|awk {print $1}` status_error=`wc -l /usr/local/zhicbo/error.txt|awk {print $1}` # if [ $status_000 -lt 25 ];then # mail -s "000狀態,網絡不可達,域名無法監控到位:" [email protected] < /usr/local/zhicbo/000.txt # fi if [ $status_error -gt 1 ];then mail -s "網絡異常,請檢查" [email protected] < /usr/local/zhicbo/error.txt # && mail -s "域名監測警報:" 75507159@etlgr.com < /usr/local/zhicbo/error.txt fi

監控域名+發送郵件