3

I noticed that my script is probably running in a wrong time (UTC maybe?). But I've added CRON_TZ into the crontab.

EDIT


It's Ubuntu 18.04, DigitalOcean.com droplet which was created from snapshot.


I've checked syntax and it is correct I think. Do you know where could be the problem?

CRON_TZ='Europe/Prague'
53 12 * * * touch /home/futilestudio/feedproject/cronsupervisor/scripts/touch0.txt

The script should be executed 12:53 Slovakia/Czech Republic time (in 24 hour format) but it wasn't - it haven't created a touch0.txt. If I execute it manually it works.

CONFIRMED

I tried to put there a command in UTC and it created a file (SK/CZ is 13:24 but UTC is 11:24 right now)

24 11 * * * touch /home/futilestudio/feedproject/cronsupervisor/scripts/touch0.txt

EDIT

It's 14:20 Prague time and I've set two jobs:

21 12 * * * TZ=Europe/Prague touch /home/futilestudio/feedproject/cronsupervisor/scripts/touch0.txt
21 14 * * * TZ=Europe/Prague touch /home/futilestudio/feedproject/cronsupervisor/scripts/touch1.txt

and removed touch0.txt from the directory.

14:21 - created /home/futilestudio/feedproject/cronsupervisor/scripts/touch0.txt

Milano
  • 613
  • All the example I see do not have quotes around the place. 2 examples: https://stackoverflow.com/questions/13289751/cron-job-in-a-different-timezone and https://serverfault.com/questions/848829/how-to-use-timezone-with-cron-tab – Rinzwind May 01 '19 at 12:04
  • @Rinzwind I tried it with and without too. The same problem. Now I tried to set 6 12 * * * and 6 14 * * * and the first one was created which means it uses UTC... – Milano May 01 '19 at 12:07
  • 1
    AH! Putting TZ=UTC in the crontab file only sets it for the cron jobs, not for cron itself. It doesn't affect the timing of the job execution. – Rinzwind May 01 '19 at 12:19
  • @Rinzwind I tried. You can see it in EDIT at the bottom of the question. – Milano May 01 '19 at 12:22
  • 1
    See https://askubuntu.com/a/266302/15811 The top part is what you need – Rinzwind May 01 '19 at 12:23
  • @Rinzwind Wow thanks, I thought it would be more straightforward. – Milano May 01 '19 at 12:26
  • @Rinzwind There was an even better way for my case but not for all cases. I just changed the server timezone. sudo dpkg-reconfigure tzdata – Milano May 01 '19 at 12:30
  • Gratz on getting there :D Feel free to dupe your question if there is one, remove it or make an answer ;-) – Rinzwind May 01 '19 at 12:37
  • Can you confirm what time your server is using, is it using UTC? date to see time/date timedatectl to see more details. – Jeff May 01 '19 at 13:06
  • @Jeff I've solved it changing server timezone. As Rinzwind mentioned, CRON_TZ is not cron timezone but rather script timezone. – Milano May 01 '19 at 13:17

1 Answers1

0

What about setting both CRON_TZ and TZ?

SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=me

CRON_TZ='Europe/Prague'

TZ='Europe/Prague'

53 12 * * * touch /home/futilestudio/feedproject/cronsupervisor/scripts/touch0.txt

sgrf
  • 1