Avatar of Christian Palacios
Christian Palacios
Flag for Canada asked on

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
Linux* cronjobs* timezone

Avatar of undefined
Last Comment
Christian Palacios

8/22/2022 - Mon
Tomas Helgi Johannsson

Hi,

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

Hope this helps. :-)

Regards,
    Tomas Helgi
Christian Palacios

ASKER
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
ASKER CERTIFIED SOLUTION
Tomas Helgi Johannsson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Favor

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
kenfcamp

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 Palacios

ASKER
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 Palacios

ASKER
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!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.