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
Kinderly WadeprogrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
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)
0
Kinderly WadeprogrammerAuthor 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).
0
omarfaridCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kinderly WadeprogrammerAuthor Commented:
Hi omar,

How can I be 100% sure that crontab is running my bash script? Thanks
0
omarfaridCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohamed MagdyCTOCommented:
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.
0
AnnlanCommented:
If your server have issue, I use a cron service called easycron.com to trigger the script to run.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.