Run bash script between time variables










-1














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.










share|improve this question



















  • 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















-1














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.










share|improve this question



















  • 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













-1












-1








-1


1





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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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












1 Answer
1






active

oldest

votes


















0














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"





share|improve this answer






















  • 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










  • 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










  • 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











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
);



);













draft saved

draft discarded


















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









0














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"





share|improve this answer






















  • 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










  • 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










  • 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
















0














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"





share|improve this answer






















  • 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










  • 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










  • 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














0












0








0






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"





share|improve this answer














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"






share|improve this answer














share|improve this answer



share|improve this answer








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 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










  • 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

















  • 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










  • 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










  • 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
















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


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto