1.创建监控脚本:
$ vi /alidata/shell/webcheck.sh

#!/bin/sh

weblist="/alidata/shell/weblist.txt"
myemail="admin@qq.com"

for list in `cat $weblist|grep -E -v "#|^$"`
do
httpcode=`curl -o /dev/null -s -w %{http_code} "$list"`
httptime=`curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total: %{time_total}\n" "$list"|grep time_total|awk -F ":" '{print $2*1000}'`

if [ $httpcode = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ]
then echo "$list is checked ok!"
else
echo "Warning: down !"
echo "$list is down!" | mutt -s "Warning: down !" $myemail
fi

if [ $httptime -ge 10000 ]
then echo "$list is timeout!" | mutt -s "Warning: timeout !" $myemail
#else echo "$list is connect ok!"
fi

done

$ chmod +x /alidata/shell/webcheck.sh

2.创建检查列表:
$ vi /alidata/shell/weblist.txt

http://www.mysite.com

3.添加计划任务:
$ crontab -e

 */ * * * /alidata/shell/webcheck.sh

注意:

1.必须先安装mutt, 用来发送邮件:
$ yum -y install mutt

2.报错:

sendmail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol

如何解决?
$ vi /etc/postfix/main.cf

inet_protocols = all

改为

inet_protocols = ipv4

3.报错:

postdrop: warning: unable to look up public/pickup: No such file or directory

如何解决?
$ /etc/init.d/sendmail stop
$ /etc/init.d/postfix start

;

linux shell脚本: 自动监控网站状态并发送提醒邮件的更多相关文章

  1. Git学习-->如何通过Shell脚本实现 监控Gitlab备份整个过程并且通过邮件通知得到备份结果?

    一.背景 Git学习–>如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器? http://blog.csdn.net/ouyang_peng/article/details/ ...

  2. Git学习-->如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器?

    一.背景 在我之前的博客 git学习--> Gitlab如何进行备份恢复与迁移? (地址:http://blog.csdn.net/ouyang_peng/article/details/770 ...

  3. shell脚本监控网站状态

    shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...

  4. linux开发脚本自动部署及监控

    linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...

  5. CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存

    CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...

  6. shell批量监控网站状态码

    shell批量监控网站状态码脚本,使用curl很慢.等我学完其他方式,在来更新. #!/bin/bash #GuoYabin yuming=`/bin/cat yuming.txt` for i in ...

  7. Linux Shell脚本攻略 读书笔记

    Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...

  8. LINUX SHELL脚本攻略笔记[速查]

    Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述 ...

  9. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

随机推荐

  1. sass高级语法的补充

    1. 继承 2.混入 3.函数 我这篇博客需要点基础才能看懂, 但我这篇博客是对上一篇的 sass高级语法 的补充 从这方面来看也无所谓了

  2. Android之WebView的使用样例——WebSetting、WebViewClient、WebChromeClient

    点击查看原文 代码直接下载http://download.csdn.net/detail/metis100/8514837 第一步,xml Manifest中要设置网络权限,否则会出先 webpage ...

  3. EffectiveJava(5)避免创建不必要的对象

    避免创建不必要的对象 1.通过延迟初始化对象提高性能 调用功能方法时调用静态工厂方法,而不是调用类时使用 2.适配器:把功能委托给一个后备对象,从而为后备对象提供一个接口的对象 3.自动装箱:优先使用 ...

  4. Spring3的quartz定时任务

    要使用定时任务,需要将quartz-1.5.2.jar加入lib,没有的话可以从下面地址下载: quartz-1.5.2.jar 有了这个再做个配置文件appctx-quartz.xml: <? ...

  5. MSSQL数据库导入导出大全二(SQL语句)

    Excel文件导入数据库多个Sheet if exists(select 1 from sysobjects where name=N'p_import_excel' and type='P')dro ...

  6. NYOJ-277-车牌号

    车牌号 时间限制:3000 ms  |  内存限制:65535 KB 难度:1 描写叙述 茵茵非常喜欢研究车牌号码,从车牌号码上能够看出号码注冊的早晚,据研究发现,车牌号码是按字典序发放的,如今她收集 ...

  7. C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用 &amp;&amp; 并查集方法)

    C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. c#关闭excel进程失败的解决方法

    解决方法如下: 1.运行命令dcomcnfg -32,打开组件服务 2.找到execl服务,属性中设置交互式用户 2.设置用户权限 3.设置IIS权限

  9. 匿名函数 invoke

    delegate string MyDele(string str); string MyFun(string str) { return str; } private void Form1_Load ...

  10. &lt;LeetCode OJ&gt; 155. Min Stack

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...