4

I run a job at specific date[Client time not local time] to send email to my clients. I use cpanel cron job i tried to use cron job with time zone

but it still sending in my local time zone

32 16 08 05 *  /usr/bin/curl CRON_TZ=Africa/Algiers https://www.example.com/SendCron.php?CronID=382 #CronID382END # z93v66 

what wrong i did using Cron_TZ ??

8

Your CRON_TZ= is in a wrong place in your crontab file, as an option attribute for /usr/bin/curl.

You should instead have it as an environment variable set before the cron entries:

CRON_TZ=Africa/Algiers 

32 16 08 05 *  /usr/bin/curl https://www.example.com/SendCron.php?CronID=382

If you need to have time zone set for a single cron entry on the same single line, it is not possible with the CRON_TZ environment variable, but you need to invoke external env (run a program in a modified environment) to change the TZ:

32 16 08 05 * /usr/bin/env TZ=Africa/Algiers /usr/bin/curl https://www.example.com/Send...

Notice that both changes the time zone for the command, not for cron daemon. The cron daemon just checks whether the fields matches current time or not, regardless of the CRON_TZ variable. The manual page for systemd-cron crontab explains this limitation:

The systemd-cron units 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.

If you need to run the schedules based on timezone, you must change the server timezone, e.g.:

ln -sf /usr/share/zoneinfo/Africa/Algiers /etc/localtime
  • but in cronjob doesnot have an area to add cron timezone .. is there any way to add it in cron entry? – Salem Ahmed May 8 '17 at 14:17
  • A crontab is a text file. Plain text files should have plenty of space and area. In this case, you can get more by adding a newline i.e. EOL sequence i.e. \n (ASCII 0x0a). Or are you possibly using some kind of off-topic web hosting control panel? – Esa Jokinen May 8 '17 at 14:25
  • Yes i have cpanel there is cron job manager – Salem Ahmed May 8 '17 at 14:54
  • thanks again .... can i set cron_tz for each cron ?? – Salem Ahmed May 8 '17 at 15:14
  • 2
    @SalemAhmed you could run 32 16 08 05 * /usr/bin/env TZ=... yourcommand ... to set it specific to a command. – thrig May 8 '17 at 18:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.