Cronjob not Running

Posted by Pete Herbert Penito on Server Fault See other posts from Server Fault or by Pete Herbert Penito
Published on 2011-03-09T05:04:47Z Indexed on 2011/03/09 8:11 UTC
Read the original article Hit count: 242

Filed under:

I have a bash script that looks like this:

#!/bin/sh

PID=`ps faux | grep libt | awk 'NR==2{print $2}'`
STATUS=`ps faux | grep libt | awk 'NR==2{print $1}'`
if [ "$STATUS" = "ec2-user" ]; then
 echo "libt already killed"
else
 sudo kill $PID
 echo "libt was killed"
fi
sleep 5
cd /home/ec2-user/libt
sudo ./libt

I have saved this file as restart.sh and when I run it like ./restart.sh, it does what its supposed to (kills the libt process and restarts it). However, now I am trying to automate the process by using cron. So I made a cron job that I want to run every 6 hours that looks like this

0 */6 * * * /home/ec2-user/restart.sh

When I run "crontab -l" I can see this print so I know it's been added properly. I should mention that the service does not have the ability to be restarted, (like "service ... restart") the process ID needs to be found, killed and then the start script needs to be ran.

I have found that this cronjob is not working, I'll log onto the box and I can tell by looking at the logs that no restart has occurred. What am I doing wrong? What can I do to troubleshoot?

Any advice would help, this is my first cron job :) Thanks!

© Server Fault or respective owner

Related posts about crontab