shell报警监控频率监控

简介:

#!/bin/sh
# Author:       xxx

# Purpose:      Moniter the web status, send a alert mail when it's not available.
export LANG=C

EMAIL=xxx@gmail.com,xxx@qq.com
LOG_FILE="/var/monitor/log/web_status_`date '+%Y%m'`.log"
TMP_EMAIL="/var/monitor/.tmp.mail.`date '+%s'`"
URL="$1" # DO NOT CHANGE IT.

if [ $2 ]
then
        sleep $2
fi

# Define function "ECHO", append the timestamp at the head of every record.
ECHO () {
printf "%s " `date '+%Y-%m-%d %H:%M:%S'`
echo $1
}

# Define function HTTP_CODE, obtain the status of web service.
HTTP_CODE () {
http_code=`curl -m 20 -o /dev/null -s -w %{http_code} $URL`
}

# Define function MAIL.
MAIL () {
echo "$URL is not available now, pls pay attention." > $TMP_EMAIL
echo "And the Server 's time is: " >> $TMP_EMAIL
date >> $TMP_EMAIL
echo >> $TMP_EMAIL
echo "------" >> $TMP_EMAIL
echo "BR" >> $TMP_EMAIL
echo "Shell Robot." >> $TMP_EMAIL
mail -s "Server Alert: $URL" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
}

n=0
HTTP_CODE
if [ $http_code -eq 200 ]
then
        ECHO "|http_code:200|+$n|webpage visit success.|$URL" >> $LOG_FILE
else
        while [ $http_code -ne 200 ]
        do
                n=`expr $n + 1 `
                ECHO "|http_code:$http_code|+$n|webpage visit failed. |$URL" >> $LOG_FILE
                if [ $n -eq 5 ]; then
                        MAIL $1; exit 0
                fi
                sleep 20
                HTTP_CODE
        done
fi
# THE END.

 

 

crontab -e

*/2 * * * * /root/mo/3.sh http://qqq.com

*/2 * * * * /root/mo/3.sh http://new.qq.com
*/2 * * * * /root/mo/3.sh http://www.11com/index.html
*/2 * * * * /root/mo/3.sh http://bbs.22.com/forum.php



本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/851232

相关文章
|
监控 安全 Shell
Shell脚本实现企业电脑屏幕监控的自动化部署与维护
企业信息安全一直是重要的议题,而屏幕监控是一种有效的手段之一。本文将介绍如何使用Shell脚本实现企业电脑屏幕监控的自动化部署与维护,并在结尾部分说明如何将监控到的数据自动提交到指定网站。
427 1
|
监控 机器人 Shell
用shell脚本编写一个监控应用服务的脚本,外发到微信群
用shell脚本编写一个监控应用服务的脚本,外发到微信群
287 1
|
监控 关系型数据库 Shell
用shell脚本编写一个监控rds数据库外发到钉钉群的脚本
用shell脚本编写一个监控rds数据库外发到钉钉群的脚本
340 1
|
监控 网络协议 Unix
Linux命令-nc(端口监控、文件传输、反弹shell等)
Linux命令-nc(端口监控、文件传输、反弹shell等)
1313 0
|
监控 网络协议 Shell
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
607 0
|
缓存 运维 监控
shell监控系统状态和资源使用命令
shell监控系统状态和资源使用命令
461 2
|
JSON 监控 Shell
用shell脚本如何获取grafana上的监控数据
用shell脚本如何获取grafana上的监控数据
700 2
|
监控 Shell
生产环境Shell脚本Ping监控主机是否存活(多种方法)
生产环境Shell脚本Ping监控主机是否存活(多种方法)
|
监控 Shell
Shell脚本监控CPU、内存和硬盘利用率
Shell脚本监控CPU、内存和硬盘利用率
|
监控 Shell
Shell脚本监控WEB服务是否正常
Shell脚本监控WEB服务是否正常