Run bash script between time variables
I need to run some task at a dynamic time presented in the variable (which value is in HH.mm.ss format) + 2 minutes from its value and less than 5 minutes. Then I could add this job to crontab to schedule it for every minute and I hope that the script will run when the time variable syncs the current time + 2 (or a bit more) minutes (but no more than 5 minutes).
Thank you.
Update:
Thanks to l0b0, all that is left is to find a way to substract 2 minutes from HH.mm.ss variable to get for example 05:28:00 after substraction from var 05:30:00. I think it must be somehow simple. Thanks for help.
bash variables time cron schedule
add a comment |
I need to run some task at a dynamic time presented in the variable (which value is in HH.mm.ss format) + 2 minutes from its value and less than 5 minutes. Then I could add this job to crontab to schedule it for every minute and I hope that the script will run when the time variable syncs the current time + 2 (or a bit more) minutes (but no more than 5 minutes).
Thank you.
Update:
Thanks to l0b0, all that is left is to find a way to substract 2 minutes from HH.mm.ss variable to get for example 05:28:00 after substraction from var 05:30:00. I think it must be somehow simple. Thanks for help.
bash variables time cron schedule
2
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail thatIf
statement and not run.
– JNevill
Nov 12 '18 at 19:02
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09
add a comment |
I need to run some task at a dynamic time presented in the variable (which value is in HH.mm.ss format) + 2 minutes from its value and less than 5 minutes. Then I could add this job to crontab to schedule it for every minute and I hope that the script will run when the time variable syncs the current time + 2 (or a bit more) minutes (but no more than 5 minutes).
Thank you.
Update:
Thanks to l0b0, all that is left is to find a way to substract 2 minutes from HH.mm.ss variable to get for example 05:28:00 after substraction from var 05:30:00. I think it must be somehow simple. Thanks for help.
bash variables time cron schedule
I need to run some task at a dynamic time presented in the variable (which value is in HH.mm.ss format) + 2 minutes from its value and less than 5 minutes. Then I could add this job to crontab to schedule it for every minute and I hope that the script will run when the time variable syncs the current time + 2 (or a bit more) minutes (but no more than 5 minutes).
Thank you.
Update:
Thanks to l0b0, all that is left is to find a way to substract 2 minutes from HH.mm.ss variable to get for example 05:28:00 after substraction from var 05:30:00. I think it must be somehow simple. Thanks for help.
bash variables time cron schedule
bash variables time cron schedule
edited Nov 13 '18 at 18:17
asked Nov 12 '18 at 18:57
Dmitry
62
62
2
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail thatIf
statement and not run.
– JNevill
Nov 12 '18 at 19:02
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09
add a comment |
2
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail thatIf
statement and not run.
– JNevill
Nov 12 '18 at 19:02
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09
2
2
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail that
If
statement and not run.– JNevill
Nov 12 '18 at 19:02
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail that
If
statement and not run.– JNevill
Nov 12 '18 at 19:02
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09
add a comment |
1 Answer
1
active
oldest
votes
at
should do the trick. Based on man at
and an offset variable $offset
you should be able to use this (untested):
echo 'some_command with arguments' | at "now + $offset"
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just meansat
has scheduled the command to run at the given time.
– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried toopen /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.
– Dmitry
Nov 13 '18 at 5:35
No,at
is not broken. What you're doing there is running the command and passing the output of it toat
, which is not at all what you want. Try using the pattern I've shown you.
– l0b0
Nov 13 '18 at 5:36
|
show 8 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53268434%2frun-bash-script-between-time-variables%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
at
should do the trick. Based on man at
and an offset variable $offset
you should be able to use this (untested):
echo 'some_command with arguments' | at "now + $offset"
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just meansat
has scheduled the command to run at the given time.
– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried toopen /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.
– Dmitry
Nov 13 '18 at 5:35
No,at
is not broken. What you're doing there is running the command and passing the output of it toat
, which is not at all what you want. Try using the pattern I've shown you.
– l0b0
Nov 13 '18 at 5:36
|
show 8 more comments
at
should do the trick. Based on man at
and an offset variable $offset
you should be able to use this (untested):
echo 'some_command with arguments' | at "now + $offset"
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just meansat
has scheduled the command to run at the given time.
– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried toopen /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.
– Dmitry
Nov 13 '18 at 5:35
No,at
is not broken. What you're doing there is running the command and passing the output of it toat
, which is not at all what you want. Try using the pattern I've shown you.
– l0b0
Nov 13 '18 at 5:36
|
show 8 more comments
at
should do the trick. Based on man at
and an offset variable $offset
you should be able to use this (untested):
echo 'some_command with arguments' | at "now + $offset"
at
should do the trick. Based on man at
and an offset variable $offset
you should be able to use this (untested):
echo 'some_command with arguments' | at "now + $offset"
edited Nov 13 '18 at 5:46
answered Nov 12 '18 at 20:51
l0b0
33.4k1584145
33.4k1584145
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just meansat
has scheduled the command to run at the given time.
– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried toopen /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.
– Dmitry
Nov 13 '18 at 5:35
No,at
is not broken. What you're doing there is running the command and passing the output of it toat
, which is not at all what you want. Try using the pattern I've shown you.
– l0b0
Nov 13 '18 at 5:36
|
show 8 more comments
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just meansat
has scheduled the command to run at the given time.
– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried toopen /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.
– Dmitry
Nov 13 '18 at 5:35
No,at
is not broken. What you're doing there is running the command and passing the output of it toat
, which is not at all what you want. Try using the pattern I've shown you.
– l0b0
Nov 13 '18 at 5:36
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
Thank you for your answer, but I tried to use 'at' right away and faced that it executes the script immediately and not at a scheduled time as its mentioned ('a new job has been added'), so I couldn't understand why it didn't work for me and thought then it could be done with another methods.
– Dmitry
Nov 13 '18 at 5:05
That message just means
at
has scheduled the command to run at the given time.– l0b0
Nov 13 '18 at 5:18
That message just means
at
has scheduled the command to run at the given time.– l0b0
Nov 13 '18 at 5:18
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
I see but using 'at' the script runs at the time I execute it despite of the added scheduled job (it doesn't start at the pointed time though), maybe something wrong with my 'at' command on my computer, I can try it on another one to see if the problem is in command and not in the script. Thanks
– Dmitry
Nov 13 '18 at 5:24
tried to
open /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.– Dmitry
Nov 13 '18 at 5:35
tried to
open /Applications/Mail.app | at 08:27
and as I said it opened the app immediately, the same on both computers, what I do wrong? I need to run another working script at a time, not just a command. Thank you.– Dmitry
Nov 13 '18 at 5:35
No,
at
is not broken. What you're doing there is running the command and passing the output of it to at
, which is not at all what you want. Try using the pattern I've shown you.– l0b0
Nov 13 '18 at 5:36
No,
at
is not broken. What you're doing there is running the command and passing the output of it to at
, which is not at all what you want. Try using the pattern I've shown you.– l0b0
Nov 13 '18 at 5:36
|
show 8 more comments
Thanks for contributing an answer to Stack Overflow!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fstackoverflow.com%2fquestions%2f53268434%2frun-bash-script-between-time-variables%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
2
You can schedule it to run every minute and perform that check (if it's within 2 and 5 minutes from some other time). Every other run will just fail that
If
statement and not run.– JNevill
Nov 12 '18 at 19:02
Thanks for your comment, but how could I write it for I am very newbie in bash? Thank you.
– Dmitry
Nov 12 '18 at 19:14
Please read over these guidelines on how to ask a good question well.
– Paul Hodges
Nov 12 '18 at 22:09