Shell如何定时监控http服务的运行状态
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍"Shell如何定时监控http服务的运行状态"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"Shell如何定时监控http服务的运行状态"文章
千家信息网最后更新 2026年11月02日Shell如何定时监控http服务的运行状态
这篇文章主要介绍"Shell如何定时监控http服务的运行状态"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"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 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" \ 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服务的运行状态"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。
监控
状态
服务
运行
方法
知识
方式
行业
语句
不同
实用
内容
写法
实用性
实际
家用
文章
更多
条件
案例
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技名片
新华互联网科技学校
互联网科技的
互联网络科技有限公司
广州互联网络科技有限公司
万达互联网科技
四川狮子座互联网科技
顺网科技2021年互联网排名
华脉科技工业互联网产品
湖南洣水互联网科技有限公司扣款
银川新华互联网科技学校地址
南山科技园互联网公司有哪些
厦门千工互联网科技有限公司
互联网科技革命什么开始
和信科技工业互联网
畅思互联网科技
爱医互联网络科技
广州有谷有贝互联网科技有限公司
万物互联网智能科技
互联网金融运营模式中的金融科技
互联网科技工作委员会
中国互联网科技工作委员会毛军
互联网科技官网
互联网科技财经
贷财互联网科技
沃里互联网科技
广州慧亚互联网科技怎么样
中国的互联网科技企业的崛起
伊宁互联网科技做什么的
锡山区互联网智能科技产品供应