./root/apachemonitor.sh &
cat apachemonitor.sh
代碼: 選擇全部
#!/bin/bash
#source:http://www.arefly.com/linux-apache-monitor/
URL="http://www.551.com.tw"
curlit() {
curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep '200'
}
doit() {
echo "CURLIT"
if ! curlit; then
sleep 20
top -n 1 -b >> /var/log/apachemonitor.log
/usr/bin/killall -9 httpd
sleep 2
/etc/init.d/httpd start > /dev/null
echo $(date) "Apache Restart" >> /var/log/apachemonitor.log
sleep 30
if ! curlit; then
echo $(date) "Restart Fail! Reboot Computer!" >> /var/log/apachemonitor.log
reboot
fi
sleep 180
fi
}
echo $(date) "Start!" >> /var/log/apachemonitor.log
sleep 300
while true; do
doit > /dev/null
sleep 10
done