Copy codeThe Code is as follows :#! /Bin/bash
If [! -F/tmp/down_count]; then
Echo "0" & gt;/tmp/down_count
Fi
Curl-I tomcat-host-o "/tmp/status" & gt;/dev/null 2 & gt; & amp; 1
Code = 'awk' NR = 1 {print $2} '/tmp/status'
If ["$ [code]"-ge 500]; then
Down = 'expr $ (cat/tmp/down_count) + 1'
Echo "$ down" & gt;/tmp/down_count
If ["$ down"-gt 3]; then
If [! -F "/tmp/restart_count"]; then
Echo "0" & gt;/tmp/restart_count
Fi
Restart_count = 'expr $ (cat/tmp/restart_count) + 1'
Echo "$ restart_count" & gt;/tmp/restart_count
If ["$ restart_count"-le 2]; then
Echo "tomcat down at 'date'" & gt;/tmp/down_info
/Etc/init. d/tomcat6 restart
Fi
Fi
Else
Echo "0" & gt;/tmp/down_count
Echo "0" & gt;/tmp/restart_count
Fi
The script is implemented. When the status code of the detected webpage is greater than or equal to 500 for three consecutive times, Tomcat 6 is automatically restarted and restarted only twice in a row.