Copy Code code as follows:
#!/bin/bash
if [!-f/tmp/down_count];then
echo "0" > /tmp/down_count
Fi
Curl-i tomcat-host-o "/tmp/status" >/dev/null 2>&1
Code= ' awk ' nr==1 {print $} '/tmp/status '
If ["$[code]"-ge];then
Down= ' expr $ (cat/tmp/down_count) + 1 '
echo "$down" > /tmp/down_count
If ["$down"-GT 3];then
if [!-F "/tmp/restart_count"];then
echo "0" > /tmp/restart_count
Fi
Restart_count= ' expr $ (cat/tmp/restart_count) + 1 '
echo "$restart _count" > /tmp/restart_count
If ["$restart _count"-le 2];then
echo "Tomcat down at ' date '" >> /tmp/down_info
/etc/init.d/tomcat6 restart
Fi
Fi
Else
echo "0" > /tmp/down_count
echo "0" > /tmp/restart_count
Fi
The script is implemented, when the detection page status code is greater than or equal to 500 consecutive 3 number of times, automatically restart Tomcat6, and only two consecutive restart.