广告
返回顶部
首页 > 资讯 > 精选 >shell脚本怎样实现定时监控http服务的运行状态
  • 767
分享到

shell脚本怎样实现定时监控http服务的运行状态

2023-06-05 20:06:42 767人浏览 薄情痞子
摘要

这篇文章主要为大家展示了“shell脚本怎样实现定时监控Http服务的运行状态”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“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 /]# 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服务的运行状态”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网精选频道!

--结束END--

本文标题: shell脚本怎样实现定时监控http服务的运行状态

本文链接: https://www.lsjlt.com/news/244337.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • shell脚本怎样实现定时监控http服务的运行状态
    这篇文章主要为大家展示了“shell脚本怎样实现定时监控http服务的运行状态”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“shell脚本怎样实现定时监控http服务的运行状态”这篇文章吧。注意...
    99+
    2023-06-05
  • Shell脚本实现监控iptables运行状态
    最近在调试服务器的iptables,自己做了个定时关iptables,但晚上回家很少开电脑,所以就没法去启动iptables,当然你可能会说,为什么不取消定时关闭iptables,我只能说个人的环境不一样,...
    99+
    2022-06-04
    脚本 运行状态 Shell
  • Linux Shell脚本监控WAS的运行状态是怎么样的
    今天就跟大家聊聊有关Linux Shell脚本监控WAS的运行状态是怎么样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。原理:通过调用 WAS 自带的脚本 wsadmin.sh 来...
    99+
    2023-06-16
  • Shell脚本实现监视指定进程的运行状态
    在之前的博客中,曾经写了自动化测试程序的实现方法,现在开发者需要知道被测试的进程(在此指运行在LINUX上的主进程的)在异常退出之前的进程的运行状态,例如内存的使用率、CPU的使用率等。 现用shell脚本...
    99+
    2022-06-04
    脚本 运行状态 进程
  • 如何实现用Shell脚本监控服务器在线状态和邮件报警
    本篇内容主要讲解“如何实现用Shell脚本监控服务器在线状态和邮件报警”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何实现用Shell脚本监控服务器在线状态和邮件报警”吧!对于服务器来说在线率...
    99+
    2023-06-09
  • 如何实现Linux服务器硬件运行状态及故障邮件提醒的监控脚本
    小编给大家分享一下如何实现Linux服务器硬件运行状态及故障邮件提醒的监控脚本,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!监控硬件运行状况shell 监控cpu...
    99+
    2023-06-09
  • Linux服务器硬件运行状态及故障邮件提醒的监控脚本分享
    监控硬件运行状况 shell 监控cpu,memory,load average,记录到log,当负载压力时,发电邮通知管理员。 原理: 1.获取cpu,memory,load average的数值 2.判...
    99+
    2022-06-04
    脚本 运行状态 故障
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作