I have a PHP web application that schedules Linux "at" jobs using the PHP function
exec(). The scheduled task is another PHP script. Somehow, under certain conditions that I suspect are related to scheduling the same job simultaneously, a job that is scheduled for well into the future is immediately executed. For instance, yesterday I was testing this functionality and an "at" job executed prematurely.
I redirect the output from the job, as limited as it is, to a file in
at_job.log. The job executed at 21:17 (9:17pm) UTC yesterday (Feb 20th), when the job was scheduled.
Here is the log file contents, as of February 21st, 17:57 (5:57pm) UTC:
.. job 72 at Thu Feb 21 23:07:00 2019 job 73 at Thu Feb 21 23:17:00 2019
And here is the "at" job queue as of the same time (February 21st, 17:57 UTC):
# atq 73 Thu Feb 21 23:17:00 2019 a staging
Wondering how this is possible, and what I did wrong to cause it. I have put in safeguards to avoid scheduling jobs at the same time since then but I'm not 100% sure that is what happened here.
Here is the command I ran below (slightly changed to hide some details):
/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20 | at -m 2206 21.02.2019 >> /var/log/at_log.log 2>&1
This appears to result in the script running immediately AS WELL as something being scheduled for later (duplicate entry was me testing the command directly in a putty window):
atq 75 Thu Feb 21 22:06:00 2019 a staging 76 Thu Feb 21 22:06:00 2019 a root 74 Thu Feb 21 21:43:00 2019 a staging