update:
when I echo $res in the script below, I get the following, I guess it's because the script itself contains the word searchd!! so at the very instant that the cronjob process gets executed, $res becomes empty!
I renamed the script, problem solved!
root 10769 7177 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_searchd.sh root 10770 10769 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_searchd.sh
original problem:
I have a shell script that works when I invoke it in the shell, but when putting in crontab in the following way, it doesn't work(not sending an email). The strange thing is that cron log shows that the process is getting ran every minute!
*/1 * * * * root /home/scripts/monitor_searchd.sh
here's the script:
process="java"
res="`ps -ef|grep $process|grep -v grep`"
if [ ! -n "$res" ]; then
echo "$process is down!" | mail -s "$process is down" [email protected]
fi
cron log
CROND[7370]: (root) CMD (/home/scripts/monitor_searchd.sh)