案例五:shell脚本实现定时监控http服务的运行状态
注意:监控方法可以为端口、进程、URL模拟访问方式,或者三种方法综合。
说明:由于截止到目前仅讲了if语句,因此,就请大家用if语句来实现。
[root@oldboy-B scripts]# cat apachemon #!/bin/sh #created by oldboy 20110523 . /etc/init.d/functions HTTPPRONUM=`ps -ef|grep http|grep -v grep|wc -l` #if [ $HTTPPRONUM -lt 1 ];then if [[ $HTTPPRONUM -lt 1 ]];then action “httpd is not running” /bin/false action “httpd is not running” /bin/false >/tmp/httpd.log httpdctl restart >/dev/null 2>&1 action “httpd is restart” /bin/true mail -s “`uname -n`’s httpd restarted at `(date)`” 31333741@qq.com exit 1 else action “httpd is running” /bin/true exit 0 fi
[root@oldboy-B scripts]# apachemon httpd is running [确定] [root@oldboy-B scripts]# pkill httpd [root@oldboy-B scripts]# ps -ef |grep http |grep -v grep [root@oldboy-B scripts]# apachemon httpd is not running [失败] httpd is restart [确定] [root@oldboy-B scripts]# ps -ef|grep http|grep -v grep root 5845 1 1 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5852 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5853 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5854 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5855 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5856 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5857 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5858 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart apache 5859 5845 0 15:59 ? 00:00:00 /usr/sbin/httpd -k restart
[root@oldboy-B /]# echo oldboytest >/var/www/html/index.htm [root@oldboy-B /]# wget –quiet –spider http://10.0.0.161/index.htm [root@oldboy-B /]# echo $? 0 [root@oldboy-B /]# ll index.htm ls: index.htm: 没有那个文件或目录
[root@oldboy-B scripts]# cat apachemon1 #!/bin/sh #created by oldboy 20110523 . /etc/init.d/functions #HTTPPRONUM=`ps -ef|grep http|grep -v grep|wc -l` #=====>这个是基于http方式进行判断 wget –quiet –spider http://10.0.0.161/index.htm #=====>这个是基于WGET URL方式进行判断 if [ $? -ne 0 ];then action “httpd is not running” /bin/false >/tmp/httpd.log httpdctl restart >/dev/null 2>&1 action “httpd is restart” /bin/true >>/tmp/httpd.log mail -s “`uname -n`’s httpd restarted at `(date)`” mail@qq.com exit 1 else action “httpd is running” /bin/true exit 0 fi
[root@oldboy-B scripts]# cat apachemon1 #!/bin/sh #created by oldboy 20110523 # . /etc/init.d/functions wget –quiet –spider http://10.0.0.161/index.htm #=====>这个是基于WGET URL方式进行判断 if [ $? -ne 0 ];then action “httpd is not running” /bin/false >/tmp/httpd.log httpdctl restart >/dev/null 2>&1 action “httpd is restart” /bin/true >>/tmp/httpd.log mail -s “`uname -n`’s httpd restarted at `(date)`” 31333741@qq.com exit 1 fi
[root@oldboy-B scripts]# cat apachemon1 #!/bin/sh #created by oldboy 20110523 # . /etc/init.d/functions HTTPPORTNUM=`netstat -lnt|grep 80|grep -v grep|wc -l` HTTPPRONUM=`ps -ef|grep http|grep -v grep|wc -l` wget –quiet –spider http://10.0.0.161/index.htm && RETVAL=$? if [ $RETVAL -ne 0 ] || [ $HTTPPORTNUM -ne 1 ] || [ $HTTPPRONUM -lt 1 ] ;then #if [ "$RETVAL" != "0" -o "$HTTPPORTNUM" != "1" -o "$HTTPPRONUM" \< "1" ] ;then action “httpd is not running” /bin/false action “httpd is not running” /bin/false >/tmp/httpd.log httpdctl restart >/dev/null 2>&1 action “httpd is restart” /bin/true mail -s “`uname -n`’s httpd restarted at `(date)`” 31333741@qq.com exit 1 else action “httpd is running” /bin/true exit 0 fi
案例五:shell脚本实现定时监控http服务的运行状态的更多相关文章
- linux shell脚本守护进程监控svn服务
最近搭建的svn服务不知道什么原因服务总是被关闭(如果你不知道怎么搭建svn可以参考linux下搭建svn版本控制软件),因此用shell脚本实现一个守护进程.用于监控svn服务是否启动,如果服务不在 ...
- 【shell脚本】自动监控tomcat服务===autoCheck.sh
自动监控tomcat服务,当tommcat服务挂掉时自动重启 一.脚本内容 [root@localhost ]# cat /root/autoCheck.sh #!/bin/bash startTom ...
- CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存
CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...
- Dubbo入门到精通学习笔记(二):Dubbo管理控制台、使用Maven构建Dubbo的jar包、在Linux上部署Dubbo privider服务(shell脚本)、部署consumer服务
文章目录 Dubbo管理控制台 1.Dubbo管理控制台的主要作用: 2.管理控制台主要包含: 3.管理控制台版本: 安装 Dubbo 管理控制台 使用Maven构建Dubbo服务的可执行jar包 D ...
- Git学习-->如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器?
一.背景 在我之前的博客 git学习--> Gitlab如何进行备份恢复与迁移? (地址:http://blog.csdn.net/ouyang_peng/article/details/770 ...
- shell脚本实例-系统监控
shell脚本监控网站并实现邮件.短信报警shell进程监控脚本(发送邮件报警)Shell脚本监控服务器在线状态和邮件报警的方法 http://www.jbxue.com/jb/shell/ 11. ...
- 用shell脚本实现定时备份数据库
1.备份数据库的方法 可以使用命令查看 ls /usr/local/mysql/bin 这个mysqldump就是系统内置的用来备份数据库的工具. 2.实现方法 ①先随便进入一个位置创建一个目录 ② ...
- Shell脚本日志关键字监控+告警
最近小张的爬虫程序越来越多,可当爬虫程序报错,不能及时的发现,从而造成某些重要信息不能及时获取的问题,更有甚者,遭到领导的批评.于是就在想有没有一种方法,当爬取信息报错的时候,可以通过邮件或者短信的方 ...
- 实验五 shell脚本编程
项目 内容 这个作业属于哪个课程 课程链接 这个作业的要求在哪里 作业要求 学号-姓名 17041428-朱槐健 作业学习目标 1. 了解shell脚本的概念及使用 2.掌握shell脚本语言的基本语 ...
随机推荐
- Zotero群组新建后无法显示
我们新建Zotero的群组后无法显示. 此时需要点击文献库,就刷新了. 修改Zotero的群组后无法显示修改后的名称 点击同步即可同步内容.
- Cesium入门6 - Adding Imagery - 添加图层
Cesium入门6 - Adding Imagery - 添加图层 Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com ...
- 2022GDUT寒假专题学习-1 B,F,I,J题
专题链接:专题学习1 - Virtual Judge (vjudge.net) B - 全排列 题目 思想 这道题可以用DFS进行求解,但是一看到全排列,其实可以立刻想到一个STL函数:next_pe ...
- 搭建服务器之DNS
DNS服务器,实用软件为bind,服务守护进程为named,一下记录一下自己的搭建过程: 1.yum install bind* 其中包括bind本身软件,测试dns的一些工具dig,nslooku ...
- 5种高大上的yml文件读取方式,你知道吗?
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. 在上一篇文章中,我们从源码角度分析了SpringBoot解析yml配置文件的全流程,那么我们今天就来点实战,总结一下除了烂大街的@Value和@ ...
- MobaXterm中文乱码问题
现在Xshell和SecureCRT都要收费,本着不用盗版的原则,同时需要标签管理session,快捷命令等功能,最后选择了MobaXterm. 但是使用后发现中文会乱码.后按照博客的方法,修改了终端 ...
- 短视频正当时,如何让你的App快速构建视频创作能力?
视频编辑服务(Video Editor Kit)是华为开放给开发者快速构建视频编辑能力的服务,提供视频导入.编辑处理.特效渲染.视频导出.媒体资源管理等一站式视频处理能力.视频编辑服务为全球开发者提供 ...
- Kubernetes:Pod基础知识总结
Blog:博客园 个人 官方文档详尽介绍了Pod的概念. 概念 Pods are the smallest deployable units of computing that you can cre ...
- 命令行传参是否只能针对main方法
先上结论 命令行传参只能针对main方法而言,而且格式严格 这里在原有主类test基础上创建了另一个类,名字为testCMD,但里面创建的方法并不是main方法,在cmd内编译后进行命令行传参,结果如 ...
- Github新安全措施:停止Git客户端账号密码登录的解决方案
今年 8 月 13 日之后,如果你还用账户密码来操作 Github 上的仓库,就会收到如下警告: remote: Support for password authentication was rem ...