My script works when ran by itself but not via crontab
Crontab
[root@someserver:/]# crontab -l
SHELL=/bin/bash
PATH=/usr/lib64/qt-3.3/bin:/home/ec2/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
*/1 * * * * /bin/bash /opt/scripts/check_beaver_status.sh
Script in question
#!/bin/bash
function check_if_beaver_running () {
current_script=`basename $0`
process_name="beaver"
/bin/ps aux | /bin/grep "${process_name}" | /bin/grep -v 'grep' | /bin/grep -v "$current_script"
if [ $? -eq 0 ]; then
echo "${process_name} running"
else
echo "${process_name}: not running, starting..."
if [ -f /var/run/logstash_beaver.pid ] ; then
/bin/rm -f /var/run/logstash_beaver.pid
fi
/sbin/service beaver start
fi
}
check_if_beaver_running
Crond wasn't running.
Also I changed my script to:
I'm very interested in the answer to this, so let me help you diagnose it.
Try changing cron to:
Also add the command:
To both the top of the script, and the bottom of the function call in the script.
Let it run once and share with us the result. Maybe on pastie.org or something.