Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a different time zone for a SPECIFIC task in crontab?

I need to add a new task for crontab which will execute it in a different TZ than the local machine time. I succeed to do it as you can see in the example below, but the problem is that from time i changed the TZ all the jobs after refers to the new TZ

    * * * * * rubHello.sh
    0 19 * * * runKuku.sh
    CRON_TZ="Europe/Rome"
    17 13 * * * /tmp/job1.sh
    0  18 * * * /tmp/Job2.sh

in the example above, job1 runs in Europe/Rome as my request, but also job2 runs in that time which is NOT OK.

it there a way to tell crontab change the TZ for only specific task and get back to default crontab TZ for the next jobs after?

Thank you.

like image 495
Asfbar Avatar asked Sep 19 '25 17:09

Asfbar


1 Answers

Try this (assuming that you're in Istanbul), CRON_TZ variable should be set before your cron entry :

* * * * * rubHello.sh
0 19 * * * runKuku.sh
CRON_TZ="Europe/Rome"
17 13 * * * /tmp/job1.sh
CRON_TZ="Europe/Istanbul"  
0  18 * * * /tmp/Job2.sh

OR

* * * * * rubHello.sh
0 19 * * * runKuku.sh
0  18 * * * /tmp/Job2.sh
CRON_TZ="Europe/Rome"
17 13 * * * /tmp/job1.sh
like image 178
Barbaros Özhan Avatar answered Sep 22 '25 07:09

Barbaros Özhan