1
#! /Bin/bash
PID = 'ps-Ef | grep tomcat8082 | grep-V grep | WC-l'
Port = 'netstat-anplt | grep 8082 | WC-l'
Path =/usr/tomcat/tomcat8082/bin/startup. Sh
If [$ pid = 1-A $ port-EQ 1]; then
Echo "Tomcat is running"
Else
Echo "tomcat8082 is stoped and now let's run it"
Sleep 3
Echo "now restart tomcat8082"
[-X $ path] & SH $ PATH>/dev/null 2> & 1 & status = "sucess" | status = "failure"
Sleep 5
PID = 'ps-Ef | grep tomcat8082 | grep-V grep | WC-l'
Port = 'netstat-anplt | grep 8082 | WC-l'
Pid8082 = 'ps-Ef | grep tomcat8082 | grep-V grep | awk '{print $2 }''
If [$ PID-ne 1-A $ port-ne 1]; then
While true
Do
Kill-9 $ pid8082
[$? -EQ 0] & break
Sleep 1
Done
[-X $ path] Sh $ Path & status = "success" | status = "failure"
Fi
Fi
~
2 #! /Bin/bash
Port = 'netstat-anplt | grep httpd | WC-l'
Process = 'ps-Ef | grep httpd | WC-l'
Path =/etc/init. d/httpd
If [$ port-EQ 1-A $ process-GT 1]; then
Echo "HTTP is running"
Else
Echo "HTTP is stopping, do you want to start httpd? "
Read-P "start [1] \ t not start [2]:"
[$ A-EQ 1] & [-x $ path] & $ PATH start
If [$ port-ne 1-o $ process-LE 1]; then
While true
Do
Pkill httpd
[$? -EQ 0] & break
Done
[-X $ path] & $ PATH start
Fi
[$ A-EQ 2] & Exit
Fi ~
3
#! /Bin/bash
# Stat = 'nmap 192.168.0.200-P 80 | grep open | WC-l'
IP = 192.168.0.200
Wget-T 10-Q 192.168.0.200
If [$? -EQ 0]; then
Echo "the HTTPd service of $ IP is running"
Else
/Etc/init. d/httpd start
Fi
~
4
#! /Bin/bash
# Stat = 'nmap 192.168.0.200-P 80 | grep open | WC-l'
[-F/etc/init. d/functions] &./etc/init. d/functions | Exit 1
Httpcode = 'curl-I-s 192.168.0.200 | head-1 | awk '{print $2 }''
If ["$ httpcode" = "200"]; then
Action "HTTP is running."/bin/true
Else
Action "HTTP is not running."/bin/false
Sleep 1
/Etc/init. d/httpd Start>/dev/null &&\
Action "nginx is started."/bin/true
Fi
~
My monitoring script