We help IT Professionals succeed at work.

cron jobs are not running in cPanel/WHM

Dear experts,

I have a VPS account with hostgator and created some scripts under crontab. Somehow my scripts are not running at the scheduled time. I've ensured that my script runs simply typing the command ./test.sh and it does update my online database. I've also noticed the path with jailshell on top of the crontab when I input crontab -e. I am wondering if my scripts are been locked?

If locked how can I resolve it by either manipulate with the settings in cPanel or WHM that will not lock my scripts? Thanks
Comment
Watch Question

Top Expert 2007

Commented:
Can you share sample script that you schedule to run with crontab?

When you write script to run under crontab, then consider:

1- set env variables that script needs, e.g. PATH
2- user full pathnames to folders and files
3- Redirect stdin, stdout & stderr as required
4- Make the script file executable (use chmod)
Kinderly Wadeprogrammer

Author

Commented:
Hi omar,

I found the issue. When I typed ps -ef and looking for my bash script named ins_update.sh, I found this line:

jailshell (loginname) [14313] -c /home/loginname/script/ins_update.sh

I assumed that somehow the script got locked up? (I have a loop in this script that loops every 5 second checking for update. It simply will read the mod date of a particular file. If the date change the script will copy that file over).

Can this be due to overloading the system? What can be the fix for this if I need to keep the update every 5 second?

all my other scripts are running fine. I have a script that will do the backup on an hourly base (works fine).
Top Expert 2007
Commented:
To avoid any overlap between cron jobs, you can do the following:

1- create a lock file:

touch /tmp/mylock$$

2- check if more than one lock is there

c=`ls /tmp/lock* | wc -l`

3- if $c is 1 then do what you want to do else do nothing

4- remove your lock

rm /tmp/lock$$

In this way you can avoid overlap of cron jobs
Kinderly Wadeprogrammer

Author

Commented:
Hi omar,

How can I be 100% sure that crontab is running my bash script? Thanks
Top Expert 2007
Commented:
You can log the run, e.g. put command like below as first line in the script:

/usr/bin/date >> /tmp/mylog (please verify path for date command)

And later check the content of /tmp/mylog file. If you see dates in the file then the cron job run otherwise not.

You could also run the bash script in verbose mode and log the execution to a file. This can be done with

 bash -x scriptname >> /tmp/myscriptlog

Do you have ssh access to the server? This can give you a way to check other logs for crontab or mail since cron will send mail to the user if there is an error in running the script.
Commented:
In cPanel, you can find cronjob logs here:

/var/log/cron

Open in new window


Could you please provide the result of this command?
egrep -i 'test.sh' /var/log/cron

Open in new window


change test.sh with your script name.

Commented:
If your server have issue, I use a cron service called easycron.com to trigger the script to run.