#!/bin/bash
#
DATE=`date "+%Y.%m.%d-%H:%M:%S"`
ACCESS_DIR=/root/curl/access
ERRO_DIR=/root/curl/erro
SUCCESS_DIR=/root/curl/success
FILE=`date "+%Y.%m.%d-%H"`
WRONG(){
cat $ERRO_DIR/$FILE | awk -F ‘ ‘ ‘{print $2$3"\n"}‘#有错误状态码的域名
}
CURL(){
for i in `cat /root/sites.txt`;do #sites.txt得先放在指定目录,里面放了你想监控的域名
STATUS_CODE=`curl -o /dev/null -s -w %{http_code} $i`
if [ $STATUS_CODE -ne 200 ];then
echo -e "$DATE $i:\t$STATUS_CODE" | tee -a $ERRO_DIR/$FILE
else
echo -e "$DATE $i:\t$STATUS_CODE" | tee -a $SUCCESS_DIR/$FILE
fi
done
}
NUM=`CURL | grep -v 200 | wc -l`
echo $NUM
if [ $NUM -ge 1 ];then
echo -e "Web site have $NUM can‘t be accessed\nWrong name is:`WRONG`" | mail -s "Web Site Down" 123456789@qq.com
else
echo "$DATE All Web Site is good" &>>$ACCESS/$FILE.log
fi
发送邮件需要的配置:
修改/etc/mail.rc (/etc/mail.rc)
set from=123456789@qq.com smtp=smtp.qq.com set smtp-auth-user=123456789@qq.com smtp-auth-password=123456789 set smtp-auth=login
from:是发送的邮箱
smtp:是发生的外部smtp服务器的地址
smtp-auth-user:是外部smtp服务器认证的用户名(你指定的邮箱)
smtp-auth-password:是外部smtp服务器认证的用户密码(邮箱的密码)
smtp-auth:是邮件认证的方式
发送一封邮件测试一下:
echo "hello,word" | mail -s "test" 123456789@qq.com
-s后面的是邮件标题
123456789@qq.com:收件人地址
本文出自 “linux” 博客,请务必保留此出处http://study89757.blog.51cto.com/8683527/1759119
原文地址:http://study89757.blog.51cto.com/8683527/1759119