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. H5性能调优

    概述 PC优化手段在Mobile侧同样适用 在Mobile侧我们提出三秒种渲染完成首屏指标 基于第二点,首屏加载3秒完成或使用Loading 基于联通3G网络平均338KB/s(2.71Mb/s),所 ...

  2. 算法导论(Introduction to Algorithms )— 第十二章 二叉搜索树— 12.1 什么是二叉搜索树

    搜索树数据结构支持很多动态集合操作,如search(查找).minmum(最小元素).maxmum(最大元素).predecessor(前驱).successor(后继).insert(插入).del ...

  3. Shell 同时读取多个文件

    现有两个文件 1.txt  2.txt,内容分别如下: [root@SHO-XXW-- readmulti]# .txt [root@SHO-XXW-- readmulti]# .txt a b c ...

  4. (CF#257)A. Jzzhu and Children

    There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number al ...

  5. DNS原理及其解析过程【精彩剖析】

    DNS原理及其解析过程[精彩剖析] 2012-03-21 17:23:10 标签:dig wireshark bind nslookup dns 原创作品,允许转载,转载时请务必以超链接形式标明文章 ...

  6. video视频播放以及主流浏览器兼容

    直接看代码吧! <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  7. 新建WORD文档打开会出现转换文件对话框3步解决办法

    1.选择“纯文本”格式打开word文件.  ------------------------------------------------------------------------------ ...

  8. C# const和static readonly区别

    [转]C# const和static readonly区别 以前只是知道Const和static readonlyd的区别在于const的值是在编译期间确定的,而static readonly是在运行 ...

  9. elk文件

    =================正则匹配 [root@web02 conf.d]# cat apache-grok.conf input{ file { path => "/var/ ...

  10. mongodb 安装及使用

    https://www.cnblogs.com/shileima/p/7823434.html