這是我在放主機裡檢查各項服務狀態的script,如果狀態是非運作中就會去restart服務。

再寫入排程設定每10分鍾就會執行這隻script一次,是個簡單又有用的小程式:D

#!/bin/bash

if [ -z "`/etc/rc.d/init.d/./named status|grep 'server is up and running'`" ]
then
        /etc/rc.d/init.d/./named start
        echo "`date +"%b %e %T"` named service is done" >> /var/log/service_test.log
fi


if [ -z "`/etc/rc.d/init.d/./httpd status|grep 'is running'`" ]
then
        /etc/rc.d/init.d/./httpd start
        echo "`date +"%b %e %T"` httpd service is done" >> /var/log/service_test.log
fi

if [ -z "`/etc/rc.d/init.d/./mysqld status|grep 'is running'`" ]
then
        /etc/rc.d/init.d/./mysqld start
        echo "`date +"%b %e %T"` mysqld service is done" >> /var/log/service_test.log
fi

if [ -z "`/etc/rc.d/init.d/./smb status|grep 'is running...$'`" ]
then
        /etc/rc.d/init.d/./smb restart
        echo "`date +"%b %e %T"` smb service is done" >> /var/log/service_test.log
fi
創作者介紹

胖虎的祕密基地

idobest 發表在 痞客邦 PIXNET 留言(0) 人氣()