Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  148] [ 0]  / answers: 1 / hits: 151665  / 3 Years ago, sat, june 19, 2021, 9:34:49

What's a simple way to run a command, say, 8 hours from now? I can think of this way:



nohup bash -c "sleep 28800 ; ./mycommand.sh" &


Is there a more "proper" way?


More From » bash

 Answers
4

You can use the at command. The at execute commands at a later time. The at utility shall read commands from standard input and group them together as an at-job, to be executed at a later time.



Usually, at is installed by default in Ubuntu, but if your release doesn't include it, install via:



sudo apt-get install at


For more information, options, examples, and others, see the manpage in man 1 at.



Example of a relative time specification (note the space between + and the duration):



at now + 8 hours -f ~/myscript.sh


You can also use convenient shorthands, like tomorrow or noon, as in



echo "tweet fore" | at teatime 


Note: This will run the command to the left of the pipe immediately - and its output (which is piped to at) will be run by at at the scheduled time. So, the above command schedules tweet fore to be run at teatime.



The example also demonstrates how you can pipe actions into at. at -c is the way you can examine scheduled actions, which you can conveniently list with their number, as with:



at -c 3

[#29691] Monday, June 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ranquctive

Total Points: 391
Total Questions: 103
Total Answers: 104

Location: South Sudan
Member since Thu, Feb 4, 2021
3 Years ago
ranquctive questions
;