Search code examples
crontimezonecentos7

Set a cron job to a specific timezone on Centos 7


I'm trying to set the cron jobs to run on a specific timezone, but I think I'm missing something.

I've tried to add TZ (And CRON_TZ) on top of the jobs in the /var/spool/cron/ file, but it doesn't seem to work.

TZ=Europe/Rome 
* * * * * /usr/local/bin/php /home/user/folder/file.php

I've installed CWP7pro


Solution

  • from the manual:

    Every * means something:

        minute 0-59
        hour 0-23
        day of month 1-31
        month 1-12 (or names, see below)
        day of week 0-7 (0 or 7 is Sun, or use names) 
    

    if you want every minute use this */1

    example:

         */15 * * 1 * means every 15 minutes on the 1st day of the month
    

    Edit /etc/crontab or use

        crontab -e (edit)
    

    CRON_TZ should be used instead of TZ or use TZ inline

        */15 * * 1 * TZ=Europe/Rome echo "do something"