Linux Labs

Inside the system: resources, kernel, processes / Stage 11 of 12

Time, time zone and synchronisation

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 5 min

The schedule follows the machine's zone

cron checks the schedule against the machine's clock in the machine's zone (in the Wiki) — that is why the export started at 9:00 UTC.

The TZ=Europe/Moscow line in a schedule file is an ordinary environment variable. cron passes it to the job, and date inside the export writes Moscow time. The minutes and hours of the schedule, though, cron reads in the machine's zone. And so it went: at 9:00 UTC the export started and wrote 12:00 MSK into its log.

There are two ways to fix it. The first is to convert the time in the schedule to the machine's zone; Moscow is UTC+3 all year round. The second is to change the zone of the whole machine with sudo timedatectl set-timezone Europe/Moscow: cron starts reading the schedule in the new zone at once, but every other job and the time in the logs move to Moscow time too. Servers usually stay in UTC: that way the logs of machines in different cities compare without conversion.

Exercise · do it

Set the export to 9 Moscow time

Make the lab-export export run at 9:00 Moscow time. Leave the machine's zone alone: other jobs on it run in UTC. The schedule is in /etc/cron.d/lab-export.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Schedule the export for 9:00 Moscow time not done yet
  • Keep the machine's zone in UTC not done yet

Step goals

0 of 2
  • Schedule the export for 9:00 Moscow time — not done yet
  • Keep the machine's zone in UTC — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Schedule the export for 9:00 Moscow time — not done yet
  • Keep the machine's zone in UTC — not done yet
Loading…