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.


# ndsd restart command
RESTART="/etc/init.d/ndsd restart"

# path to pgrep
PGREP="/usr/bin/pgrep ndsd"

# find ndsd pid

if [ $? -ne 0 ]
echo "NDS has been restarted." | mail -s 'Server NDS Crash' insert_email
This code works great from within shell with a simple ./FILENAME.sh
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?