11

My cron jobs are computed one hour later compared to server time. I don't understand what is going on.

My configuration is the following :

Server time :

Europe/Paris

In /etc/default/cron I added the following line :

TZ="Europe/Paris"

Despite that, cron job are launched one hour later than server time. What is really tricky, is that if I ask cron to play instruction "date", it gives the server date (the good one !).

I have no idea of how to resolve this problem ; I've been doing some reading on forums, but found nothing interesting.

What do you think ?

2
  • 4
    So cron jobs are being scheduled in UTC. The Vixie cron man page says, "The daemon will use, if present, the definition from /etc/timezone for the timezone." What's in /etc/timezone? Have you modified /etc/timezone more recently than the cron process was started? Have you tried /etc/init.d/cron restart? Commented Jan 5, 2012 at 11:11
  • 3
    /etc/timezone has been modified recently, without restarting /etc/init.d/cron . I'm gonna try to restart it. Commented Jan 5, 2012 at 12:35

5 Answers 5

16

(Copying my comment as an answer, since it turned out to be the solution; I guessed right.)

So cron jobs are being scheduled in UTC (Europe/Paris is at a one hour offset from UTC).

The Vixie cron man page says:

The daemon will use, if present, the definition from /etc/timezone for the timezone.

What's in /etc/timezone? Have you modified /etc/timezone more recently than the cron process was started? Have you tried

/etc/init.d/cron restart

?

3

Some distros such as Fedora provide a mechanism where you can set CRON_TZ= to override your default timezone.

From the Fedora man 5 crontab

The CRON_TZ variable specifies the time zone specific for the cron table. The user should enter a time according to the specified time zone into the table. The time used for writing into a log file is taken from the local time zone, where the daemon is running.

Something like this:

#m  h           d   m   wday    command
CRON_TZ="Europe/Paris"
5   0,6,12,18   *   *   *       /path/to/script.bash
1

Wikipedia says

Most cron implementations simply interpret crontab entries in the system time zone setting under which the cron daemon itself is run. This can be a source of dispute if a large multiuser machine has users in several time zones, especially if the system default timezone includes the potentially confusing DST. Thus, a cron implementation may special-case any "TZ=" environment variable setting lines in user crontabs, interpreting subsequent crontab entries relative to that timezone

So perhaps your login ID has a TZ setting that differs from the system TZ setting?

1

Restarting cron was what I needed but for me the command was

/etc/init.d/crond restart (crond not cron)
0

Just figured this out on Ubuntu 14/16. Worked perfectly for me.

Steps (sudo implied):

  1. cat /etc/timezone
  2. rm -fv /etc/localtime
  3. ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
  4. apt install -y --reinstall tzdata
  5. /etc/init.d/rsyslog restart
  6. tail -f /var/log/syslog
  7. cat /etc/timezone
2
  • Where does cron get restarted?
    – DavidPostill
    Commented Feb 14, 2017 at 16:25
  • I didn't need to restart cron. Commented Feb 14, 2017 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .