Linux “At” Job Executes Immediately
Clash Royale CLAN TAG#URR8PPP
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 /var/log/
called 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.
UPDATED:
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
linux at
add a comment |
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 /var/log/
called 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.
UPDATED:
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
linux at
1
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)
– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
1
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
Does the PHP command output the commands to execute?at
reads the commands to execute from its standard input.
– Kusalananda
Feb 21 at 20:38
add a comment |
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 /var/log/
called 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.
UPDATED:
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
linux at
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 /var/log/
called 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.
UPDATED:
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
linux at
linux at
edited Feb 21 at 20:17
Matt Aikens
asked Feb 21 at 18:01
Matt AikensMatt Aikens
11
11
1
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)
– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
1
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
Does the PHP command output the commands to execute?at
reads the commands to execute from its standard input.
– Kusalananda
Feb 21 at 20:38
add a comment |
1
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)
– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
1
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
Does the PHP command output the commands to execute?at
reads the commands to execute from its standard input.
– Kusalananda
Feb 21 at 20:38
1
1
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to
/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)– G-Man
Feb 21 at 18:29
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to
/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
1
1
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
Does the PHP command output the commands to execute?
at
reads the commands to execute from its standard input.– Kusalananda
Feb 21 at 20:38
Does the PHP command output the commands to execute?
at
reads the commands to execute from its standard input.– Kusalananda
Feb 21 at 20:38
add a comment |
1 Answer
1
active
oldest
votes
This looks as a misunderstanding of where at
gets the commands to execute from.
The at
command reads the command to execute from its standard input.
If you want at
to execute your php
command at a particular time, you need to feed that command (not the output of it) into at
:
echo '/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20' | at ...
Alternatively,
at ... <<END_JOB
/usr/bin/php
-q /PATH/TO/PHP/SCRIPT/cli_admin.php
cli product_list_edit 20
END_JOB
(where ...
are the option for at
).
Or, to read the commands from a file,
at -f filename ...
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502140%2flinux-at-job-executes-immediately%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This looks as a misunderstanding of where at
gets the commands to execute from.
The at
command reads the command to execute from its standard input.
If you want at
to execute your php
command at a particular time, you need to feed that command (not the output of it) into at
:
echo '/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20' | at ...
Alternatively,
at ... <<END_JOB
/usr/bin/php
-q /PATH/TO/PHP/SCRIPT/cli_admin.php
cli product_list_edit 20
END_JOB
(where ...
are the option for at
).
Or, to read the commands from a file,
at -f filename ...
add a comment |
This looks as a misunderstanding of where at
gets the commands to execute from.
The at
command reads the command to execute from its standard input.
If you want at
to execute your php
command at a particular time, you need to feed that command (not the output of it) into at
:
echo '/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20' | at ...
Alternatively,
at ... <<END_JOB
/usr/bin/php
-q /PATH/TO/PHP/SCRIPT/cli_admin.php
cli product_list_edit 20
END_JOB
(where ...
are the option for at
).
Or, to read the commands from a file,
at -f filename ...
add a comment |
This looks as a misunderstanding of where at
gets the commands to execute from.
The at
command reads the command to execute from its standard input.
If you want at
to execute your php
command at a particular time, you need to feed that command (not the output of it) into at
:
echo '/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20' | at ...
Alternatively,
at ... <<END_JOB
/usr/bin/php
-q /PATH/TO/PHP/SCRIPT/cli_admin.php
cli product_list_edit 20
END_JOB
(where ...
are the option for at
).
Or, to read the commands from a file,
at -f filename ...
This looks as a misunderstanding of where at
gets the commands to execute from.
The at
command reads the command to execute from its standard input.
If you want at
to execute your php
command at a particular time, you need to feed that command (not the output of it) into at
:
echo '/usr/bin/php -q /PATH/TO/PHP/SCRIPT/cli_admin.php cli product_list_edit 20' | at ...
Alternatively,
at ... <<END_JOB
/usr/bin/php
-q /PATH/TO/PHP/SCRIPT/cli_admin.php
cli product_list_edit 20
END_JOB
(where ...
are the option for at
).
Or, to read the commands from a file,
at -f filename ...
edited Feb 21 at 20:41
answered Feb 21 at 18:25
KusalanandaKusalananda
136k17257425
136k17257425
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502140%2flinux-at-job-executes-immediately%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
(1) I don’t understand. What are you showing us in the first code block? Is that “the output from the job, as limited as it is”, which you write to
/var/log/at_job.log
(which is what you seem to be saying)? What does it mean? What is it supposed to prove? (2) Imagine that you’re explaining this problem to somebody who isn’t you and can’t read your mind. (That shouldn’t be hard, because this is what you are doing.) Try to think of all the information that such a person would need to be told in order to understand your question, and provide that information. … (Cont’d)– G-Man
Feb 21 at 18:29
(Cont’d) … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 21 at 18:29
1
Please show the code used for scheduling and logging.
– Kusalananda
Feb 21 at 18:31
I have edited my question. Thanks for the feedback.
– Matt Aikens
Feb 21 at 20:36
Does the PHP command output the commands to execute?
at
reads the commands to execute from its standard input.– Kusalananda
Feb 21 at 20:38