Crontab + timezone



I have the following entry in my crontab:

0 0 * * * /home/…/ > /home/…/toto.log 2>&1

Because my time zone is +9 that servers one, my script is running at 9:00 am instead of midnight. I set the timezone environnement variable and I get the correct system date but the script is still running at 9:00 am.

I read in the wiki that “Due to security concerns, DreamHost cron does NOT have an environment”, so i guess that TZ variable is not taken in account.

Is there another way to make my script run at the correct time?




Why not change it to:
0 15 * * * /home/…/ > /home/…/toto.log 2>&1

Then it runs at -9 from DreamHost midnight which will be your midnight.




I thought about that, but the fact is that my script is a sort of agenda that reads a text file that contain dates and events.

So if i do it that way, my script will notify me for an event the day after at midnight… a bit late :slight_smile: currently it notifies me at 9:00 that it’s almost ok… but if someone knows another way to fix this, it would be perfect.




I assume you’ve written the script so you can adjust the start time appropriately and set the time zone relative to your own for the script, right?

I remember the bad old days when cron wasn’t multiuser.



I don’t understand very well what you mean… my script is really simple, it just reads a text file like :

22/11;go to the doctor
25/11;go to the swimming pool

and send me a mail if it finds that today’s date correspond to an event inside the list, so in this case i should get a mail on november 25th at midnight, reminding me I have go to the swimming today. But i receive it at 9.00 am.

I set the time zone relative to my place in my environnent variable: $TZ=Europe/Paris and I have the right time on my shell, but my script still runs at L.A.'s time when it’s run by the cron…

Any ideas?



Easy, reschedule the script to run at 1500 (3pm LA, midnight Paris.) and set the timezone in your script before processing. If you don’t do that you’ll probably miss your events for that day. (because it’ll still be the 24th in LA for 9 hours after Paris.)

Sorry this seems a bit convoluted.



Ok I got it… now it works fine :slight_smile: