0

I need to run a cron job with the following expression */20 16-23 * * * by my time zone ( Africa/Cairo ) on my Cpanel shared hosting.

I created the cron job successfully but it has done by server time/zone ( USA I guess ). after a lot of searches, I found a solution ( didn't fix my problem ) that is put a TZ="Africa/Cairo" before my command so the whole line something like this.

*/20 16-23 * * * TZ="Africa/Cairo" curl example.com

And unfortunately, it didn't work for me! as after 12 am by my time/zone the cron job still working which shouldn't!!

( */20 16-23 * * * ) every 20 min between 4 pm and 12 am

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
hesham shawky
  • 1,073
  • 4
  • 21
  • 44
  • Is it running as US or GMT? I've not seen that `TZ` before but couldn't you just do the offset from server time and your timezone? – user3783243 Jun 30 '20 at 19:11
  • I got it from here https://stackoverflow.com/questions/13289751/cron-job-in-a-different-timezone, and I am not sure, what the server time zone is! – hesham shawky Jun 30 '20 at 19:18
  • Run `date` from the shell. – user3783243 Jun 30 '20 at 19:20
  • Tue Jun 30 15:23:09 EDT 2020 – hesham shawky Jun 30 '20 at 19:23
  • Rather than changing timezone for whole server why not just check that how many hours ahead you are, calculate the time difference and move cronjob that many hours so that it works accordingly. – Keral Patel Jul 04 '20 at 03:08
  • I'm doing that already, you could say I was searching for the best solution for this if their code can do the tweak, And of course, changing the server time zone for me not an available option in fact. I was hooping there an option with crontab to do this. – hesham shawky Jul 04 '20 at 04:25

0 Answers0