Results 1 to 1 of 1
I have a script that checks for a process (by returning a simple pgrep value), if it doesn't find the pid, it will restart the service.
Code:
#!/bin/bash
# ndsd ...
- 11-17-2011 #1Just Joined!
- Join Date
- May 2009
- Location
- Illinois
- Posts
- 7
SLES 10.3 Run shell script from cron to restart service
I have a script that checks for a process (by returning a simple pgrep value), if it doesn't find the pid, it will restart the service.
This code works great from within shell with a simple ./FILENAME.shCode:#!/bin/bash # ndsd restart command RESTART="/etc/init.d/ndsd restart" # path to pgrep PGREP="/usr/bin/pgrep ndsd" # find ndsd pid $PGREP if [ $? -ne 0 ] then $RESTART echo "NDS has been restarted." | mail -s 'Server NDS Crash' insert_email fi
It will check for the pid, if not found, it WILL restart it.
The issue I have, is when it is being run from cron, it will not restart the service.
The script runs in cron. I can tell because I get the email saying that it has crashed, but it does not start it back up.
Also, since it does not restart, I get numerous emails (one for each time the job runs in cron. Every 5 minutes).
As a matter of fact, I have ran multiple different shell scripts from cron, and none will start/stop/restart any service. Is there something I'm missing?


Reply With Quote