程式碼:
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
if [ "$1" = "local" ];
then
rcd="/usr/local/etc/rc.d"
service="$2"
else
rcd="/etc/rc.d"
service="$1"
fi
status=` $rcd/$service status|grep 'is not running' `
if [ "$status" ];
then
echo "$1 is not running, auto restart..."
$rcd/$1 start
fi
用法:
rcd_service_mon.sh service_name 或 rcd_service_mon.sh local service_name
例:
1. 對named作用: rcd_service_mon.sh named
2. 對 apache 2.2 作用: rcd_service_mon.sh local apache22
詳細解說:
簡單說就是把手動的事情變成自動, 程式自動呼叫rc.d下的啟動用shell script, 並加上 status以得知狀態, 然後過濾輸出確認是否為沒在運作的狀況, 若沒在運作就嘗試啟動之.
沒有留言:
張貼留言