Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor the running status of http service regularly by Shell

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to regularly monitor the running status of http services by Shell". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to regularly monitor the running status of http services by Shell" can help you solve the problem.

Note: monitoring methods can be port, process, URL emulated access, or a combination of three methods.

Description: as only the if statement has been spoken so far, please use the if statement to achieve.

[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 [OK] [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 [failed] httpd is restart [OK] [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 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 script improvements when in real use Remove [root@oldboy-B scripts] # cat apachemon1 #! / bin/sh # created by oldboy 20110523 # if some output is not needed. / etc/init.d/functions wget-quiet-spider http://10.0.0.161/index.htm # = > this is based on the WGET URL method to judge 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 multiple condition judgment [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`netstat `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 on "how Shell monitors the running status of http services on a regular basis" ends here Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report