1

I've a script set in cronjob to run at 00 hours but it runs 5 hours earlier ie at 7PM local of earlier day. I mean it was supposed to run at local 00 hours of local time but it ran at 00 hours of UTC/GMT.

     timedatectl output
     ===================
      Local time: Wed 2020-12-02 01:33:31 EST
  Universal time: Wed 2020-12-02 06:33:31 UTC
        RTC time: Wed 2020-12-02 06:33:31
       Time zone: America/Toronto (EST, -0500)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2020-11-01 01:59:59 EDT
                  Sun 2020-11-01 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2021-03-14 01:59:59 EST
                  Sun 2021-03-14 03:00:00 EDT

 ls -lrt /etc/localtime output
================================
lrwxrwxrwx. 1 root root 35 Nov 24 11:43 /etc/localtime -> /usr/share/zoneinfo/America/Toronto
date output
============
Wed Dec  2 01:42:28 EST 2020

There is no any file called /etc/default/cron on my system. BUT CRON RUNS WITH LOCAL TIME AFTER CRON DAEMON RESTART . So the issue is before restart i.e. after the system is instantiated/made cron takes UTC time but when cron is restarted on any node, it runs fine with local time. Is it something like the cron has already started with default timezone (UTC) before the symlink of /etc/localtime was set to /usr/share/zoneinfo/America/Toronto? If yes, how can i change the timezone before cron starts?

hostnamectl output
==================
   Static hostname: abcxyz-0
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 88d24fe7c825442dbfd3b56fd0b24980
           Boot ID: 384ea93dcb604bb2ac5bec074539a7cb
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.el7.x86_64
      Architecture: x86-64

I tried to take help from https://askubuntu.com/questions/54364/how-do-you-set-the-timezone-for-crontab and https://serverfault.com/questions/791713/what-time-zone-is-a-cron-job-using#:~:text=Cron%20job%20uses%20the%20server's,the%20date%20command%20in%20terminal. but they couldn't be any useful.

1 Answers1

0

If you haven't set the hardware time to match system time, then cron's going to work off hardware time

Personally, I never run servers in anything but UTC - using local time of any form gets very complicated when managing more than a couple hobby boxes

I've been in environments running as many as half a million server endpoints (let alone desktops).

Don't use local time!

warren
  • 17,829
  • 23
  • 82
  • 134