# 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