ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What’s the best way to specify a time and day for which to defer a command?
So if I want to defer any command that comes in between 5 and 6pm Sunday through Thursday….I know I need to sleep for 60m but how do I specify the day/time for when to start and end the deferment? Thank you
Tho I’ll admit that “command that comes in” isn’t at all clear...
I had thought about Cron but the issue with this are alerts won’t always come in between 5-6pm, but if they do I need the bash file to NOT execute until 6:01pm.
I’m only familiar with how to use cron to perform a function at a certain time.
Ah. Do you already have a script that processes the alerts? Use at (man at) inside that script to control when to execute the processing.
Hard to be mor specific without more details.
Yes that is correct. I have a script that does everything it is supposed to do 24/7 for incoming alerts. Now I just need to add in a couple lines to still accept incoming alerts between 5 and 6pm each day but defer the reaction to those alerts till 6:01pm each day.
Another option is to just calculate the number of seconds to sleep. Using timestamps (seconds since 1970-01-01 00:00:00 UTC) and the date command, it's very easy to calculate.
probably a flag? You will stop "the reaction to those alerts" when it was set and unset it at 6:00. I still do not understand when and how should it be set.
So the script must start at 5am and must execute its final command after 6am, correct?
And you already know how to start it at 5am, correct?
The rest should be easy, maybe post #6.
Also, for added code golf: you can use the $SECONDS variable instead of date. 'man bash'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.