0

Consider the following cron job:

* 22-23 * * * /usr/bin/curl -u username:paswword http://api.example.com/api/test2.php

Now, according to this, the cron job must run every minute starting from 22h00 (UTC) but it doesn't. It starts before that time and also not for the full hour. So I wrote the execution time to a database table, just to see what's going on. Here is what I get:

database entries screenshot

The systemDateTime represents when the cron job executes. As you can see, it only executed 6 times and it started about 6 minutes before the scheduled time.

Is this system configuration related? The cron job is on a Apache shared server. Am I missing something or what?

Update: I use the following PHP code to get the system date time and my timezone date time:

$systemDateTime = date('Y-m-d H:i:s');
$dateNow = new DateTime("now", new DateTimeZone('GMT+2'));
$zoneDateTime = $dateNow->format('Y-m-d H:i:s');  
8
  • Note that although it doesn't address your pre-start concern, * 22-23 * * * is actually two hours and should run from 22:00 to 23:59 inclusive Commented Jan 25 at 23:36
  • What does the following command produce on your system, please: date; date +'%Z %z'; date --utc. I'm also wondering what timezone your crontab is configured to use Commented Jan 25 at 23:39
  • Your first comment is helpful. Where do I execute that command? I tried in cronjob and got email with: /usr/local/cpanel/bin/jailshell: -c: line 0: unexpected EOF while looking for matching `'' /usr/local/cpanel/bin/jailshell: -c: line 1: syntax error: unexpected end of file. Commented Jan 26 at 0:42
  • How do I see what timezone crontab is configured to use? I have a shared server and use cpanel 110.0.20 Commented Jan 26 at 0:44
  • "Where do I execute that command" - in a shell - in a terminal session. (It will fail under cron because % is a special character there) Commented Jan 26 at 8:17

1 Answer 1

0

Adding the timezone in the command seems to do the trick. Here is the new cron job:

* 22 * * * TZ=GMT+2 /usr/bin/curl -u username:password http://api.example.com/api/test2.php

Also, I'm not sure why it only executed 6 times with the first cron job but it's working fine now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .