Write a Cronjob on CloudLinux server to run a sh file to restart a service periodicly

armin654

Well-Known Member
Feb 12, 2014
45
0
6
cPanel Access Level
Root Administrator
Hello there
I want to write a crobjob to restart a specific service periodically

I wrote my command in a .sh file. When i run the .sh file manually it works fine and the service is being restarted but if i add it in cronjob and specifying a time to run that .sh file, the command is not being run .

Is there anyway to read the logs of cronjobs ? do you have any experience on this issue?
Kind regards
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello :)

Cron jobs are logged to:

/var/log/cron

Out of curiosity, which service is it and why are you having to restart it?

Thank you.
 

dalem

Well-Known Member
PartnerNOC
Oct 24, 2003
2,983
159
368
SLC
cPanel Access Level
DataCenter Provider
try putting in

/bin/sh /pathtoshfile/
if that does not call it then add
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
to the top of your crontab
 

armin654

Well-Known Member
Feb 12, 2014
45
0
6
cPanel Access Level
Root Administrator
Dear cPanelMichael! Thank you for your care about my issue. It is just a try on my LAB machine and not something seriously.
Thank you for the log location
try putting in

/bin/sh /pathtoshfile/
if that does not call it then add
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
to the top of your crontab
Thank you dalem!
The problem was that when we call the service, we should give the complete path to it and not just writing the service name.
Your help guided me to the answer.
Thank you so much
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
I am happy to see the issue is now resolved. Thank you for updating us with the outcome.