Here is a simple script that will check if your specified service is running and will start it if it’s stopped.
You will have to replace “replace_me_with_a_valid_service” with the name of the service you want to check
1 2 3 4 5 6 7 8 9 |
#!/bin/bash service=replace_me_with_a_valid_service if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then echo "$service is running!!!" else /etc/init.d/$service start fi |
You can place it in crontab and have it executed automatically
eg. to check every minute, insert into cron
1 |
* * * * * /path/to/script |
Fonte: http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/
Facebook Comments