Shatrughan Kamat
Shatrughan Kamat

Reputation: 101

How to setup to use local time in cron schedule?

Cron by default uses UTC time zone. How to set it up to use Local time (say CST) in the cron expression (for cron schedule).

Upvotes: 9

Views: 16103

Answers (2)

rndmGuy
rndmGuy

Reputation: 178

You can set your system's time zone to the intended time zone and then state the time for that zone in the cron job:

sudo timedatectl set-timezone America/New_York

and confirm typing timedatectl, or do

sudo dpkg-reconfigure tzdata

After changing the time zone, make sure to restart cron:

sudo service cron restart

Cron job:

30 5 * * * echo "run at half past 5" >> ~/logfile.log 2>&1

Upvotes: 13

RichG
RichG

Reputation: 9916

Cron doesn't care about time zone. It compares the current time to the cron string and executes the job if they match.

Upvotes: -3

Related Questions