WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Cron using UTC time?  (Read 2294 times)

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Cron using UTC time?
« on: November 29, 2016, 02:16:19 AM »
I was able to fix my RasPi's time by using the timezone file.  When I use the date command, it prints the right time.

However, when I use cron to echo the date command to a file, it uses UTC time.  Why?  Is there a way to fix this?

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Cron using UTC time?
« Reply #1 on: November 29, 2016, 04:57:26 AM »
Looks like if I use the cron bootcode, it uses UTC time no matter if I use the timezone file or not.  If I stop/start it when booted up, the time cron sees is the local time.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: Cron using UTC time?
« Reply #2 on: November 29, 2016, 05:56:39 AM »
Set your timezone on the commandline.   Look at the TZ  bootcode

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Cron using UTC time?
« Reply #3 on: November 29, 2016, 01:13:39 PM »
Set your timezone on the commandline.   Look at the TZ  bootcode

Yes that is correct, you need to set both "tz=" and "cron" bootcodes. Check /etc/init.d/tc-config to see how it works.

Here is the crontab file I used to test everything is working OK. The filename, contents and timestamp should match.

Code: [Select]
$ crontab -l -u root

*/1 0 * * * date >> /tmp/crontime0
*/1 1 * * * date >> /tmp/crontime1
*/1 2 * * * date >> /tmp/crontime2
*/1 3 * * * date >> /tmp/crontime3
*/1 4 * * * date >> /tmp/crontime4
*/1 5 * * * date >> /tmp/crontime5
*/1 6 * * * date >> /tmp/crontime6
*/1 7 * * * date >> /tmp/crontime7
*/1 8 * * * date >> /tmp/crontime8
*/1 9 * * * date >> /tmp/crontime9
*/1 10 * * * date >> /tmp/crontime10
*/1 11 * * * date >> /tmp/crontime11
*/1 12 * * * date >> /tmp/crontime12
*/1 13 * * * date >> /tmp/crontime13
*/1 14 * * * date >> /tmp/crontime14
*/1 15 * * * date >> /tmp/crontime15
*/1 16 * * * date >> /tmp/crontime16
*/1 17 * * * date >> /tmp/crontime17
*/1 18 * * * date >> /tmp/crontime18
*/1 19 * * * date >> /tmp/crontime19
*/1 20 * * * date >> /tmp/crontime20
*/1 21 * * * date >> /tmp/crontime21
*/1 22 * * * date >> /tmp/crontime22
*/1 23 * * * date >> /tmp/crontime23

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Cron using UTC time?
« Reply #4 on: November 29, 2016, 02:27:54 PM »
Thanks!

Offline 43str4ng3r

  • Newbie
  • *
  • Posts: 9
Re: Cron using UTC time?
« Reply #5 on: May 28, 2017, 04:05:59 AM »
Set your timezone on the commandline.   Look at the TZ  bootcode

Could you please elaborate on how to do this.
I'm amiss...

Thanks for your help.

43S

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Cron using UTC time?
« Reply #6 on: May 28, 2017, 04:51:22 AM »

Offline polikuo

  • Hero Member
  • *****
  • Posts: 714
Re: Cron using UTC time?
« Reply #7 on: May 28, 2017, 05:05:14 AM »

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Cron using UTC time?
« Reply #8 on: May 28, 2017, 05:06:01 AM »
I stuck the timezone correction just before the call to the script in crontab.

*/5 * * * * TZ=EST-10 date >> /tmp/date.log
http://forum.tinycorelinux.net/index.php/topic,17638.msg106134.html#msg106134

Offline 43str4ng3r

  • Newbie
  • *
  • Posts: 9
Re: Cron using UTC time?
« Reply #9 on: May 29, 2017, 10:26:34 AM »
Problem solved.

Thanks for your help.  ;)

43S