歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Linux下檢測Apache運行狀態的腳本

定時檢測apache是否啟動,如果沒啟動,自動啟動該服務
#!/bin/sh
check_services()
{
echo "Check services..."
services=""
if [ -z "`ps -A|grep httpd`" ]
then
services="$services httpd"
fi
}
start_services()
{
echo "Start services..."
for start_services in `echo $services`
do
/etc/init.d/$start_services start
done
echo
}
check_services
echo
echo "Check services succeed!"
echo
start_services
echo
echo "Start services succeed!"
echo

此腳本加入到計劃任務中,實現定時檢測服務的運行狀況。
*/1 * * * * root /user/bin/httpcheck.sh

在/etc/crontab中加入以上代碼,重啟crond服務以後,即可實現每分鐘檢測一下服務的運行狀況。

Copyright © Linux教程網 All Rights Reserved