Change the time zone of a cronjob
This will likely depend on your OS and it's implementation of cron
. This is not possible in the most popular cron implementation, vixie/isc cron
. From the crontab(5) manpage
:
LIMITATIONS
The cron daemon runs with a defined timezone. It currently does not
support per-user timezones. All the tasks: system's and user's will
be run based on the configured timezone. Even if a user specifies
the TZ environment variable in his crontab this will affect only
the commands executed in the crontab, not the execution of the crontab
tasks themselves.
Expanding on @Cyrus answer this is what I did:
I made a script which checked a UTC offset:
#!/bin/bash
export TZ=":US/Eastern"
if [ "$(date +%z)" == "$1" ]; then
shift
exec $@
fi
Then I add two crontab entries each for the offset I want:
0 8 * * * run-only-with-tz.sh -0400 place_your_command_here
0 9 * * * run-only-with-tz.sh -0500 place_your_command_here
Move your cronjob to 8:00 and sleep one hour if you are in GMT+1
0 8 * * * [ "$(date +\%z)" = "+0100" ] && sleep 3600; place_your_command_here