# vi /usr/local/sbin/check-service.sh #!/bin/bash if [ $1 = 'help' ] || [ $1 = 'usage' ] || [ $1 = 'man' ] then echo "usage:# check-service.sh service" else service=$1 script="/etc/init.d/$service" if ! $script status | grep -q "pid" then $script stop > /dev/null 2>&1 $script start echo "$service is restarted." else echo "$service already runs." fi fi
![サービス監視スクリプトを作成して cron に登録 〜 CentOS6](https://cdn-ak-scissors.b.st-hatena.com/image/square/b27ba1d703068fc4853ea1271440cbb779e7cabb/height=288;version=1;width=512/https%3A%2F%2Feasyramble.com%2Fwp-content%2Fuploads%2F2016%2F03%2Feasyramble_ogp.jpg)