We help IT Professionals succeed at work.

Oracle Linux Cron Job Runs at Wrong Time of Day

Hi there,

We have a cron job on an Oracle Linux 7 server that should run at 10PM CST every night, but some odd reason, it runs at 3PM MST.  We have checked the cron job details and it does say 21:00, for 9PM.  When I run "date", I get a time that shows CST as the timezone, but the cron job doesn't seem to be checking this.  Anything I should check/configure?

Thanks,
- Christian
Comment
Watch Question

Tomas Helgi JohannssonDatabase Administrator / Software Engineer

Commented:
Hi,

Look at this link
https://www.the-art-of-web.com/system/cron-set-timezone/

Hope this helps. :-)

Regards,
    Tomas Helgi
Christian PalaciosSenior IT Systems Administrator

Author

Commented:
Hi there,

Thanks for the article.  There is a lot of information in it, is the best solution just to add the "TZ=" entry in the cron file?  

-Christian
Database Administrator / Software Engineer
Commented:
Hi,


It is certainly worth trying to see if that solves your problem temporarely while you look for other configurations on your server that may cause this.
And yes, just add the TZ= entry above the desired line as shown in the link.

Regards,
   Tomas Helgi
David FavorFractional CTO
Distinguished Expert 2019

Commented:
As Christian stated, adding TZ= to your crontab file fixes CRON.

This may or may not be sufficient.

To set a machine/process wide timezone, do this...

ln -sf /usr/share/zoneinfo/US/Central /etc/localtime
service cron restart
service ntpd restart

Open in new window


Note: This only fixes timezone... at the server level... for new processes...

Currently active processes, do not change.

To ensure all processes run in the same timezone, a hard reboot is required.
should run at 10PM CST every night, but some odd reason, it runs at 3PM

I'm assuming the server has (displays) the correct time?
Christian PalaciosSenior IT Systems Administrator

Author

Commented:
David,

Thank you, I will try your suggestion out too.  I tried the TZ= entry in the cron job file, but the file still ran at a different time yesterday.  For your suggestion, I noticed there isn't already a link enabled as /etc/localtime doesn't have anything linked to it.  If I add this link, do I have to for sure restart the server?  If so, I will schedule a time to restart it tonight as it's a production server and I can't restart it during business hours.

Thanks,
- Christian
Christian PalaciosSenior IT Systems Administrator

Author

Commented:
Thank you Tomas and David.  The TZ= entry in the cron file fixed the issue, and the symbolic link command helped with the entire server.  Everything is working as it should!