Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Run a command *later*

+2
−0

How can I run a command later? I'm looking for a CLI way to schedule a command to be run later.

I know that I could create a systemd timer, install it, activate it... That is too much work. I want something like runlater 10min some_cmd and some_cmd runs 10 min later.

I don't want to do sleep 600 && some_cmd because that will block. After I schedule the program to run later, I want to go back to my shell, do some other stuff, close the terminal, and the command should still execute when it's time.

If I schedule a program for 10 mins later and shut down the computer 8 mins later, I don't really care what happens. The program can end up being not run. A notification about it the next time I boot up would be nice, but otherwise I'm thinking of situation where the uptime will not be interrupted.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Note that you can always do `sleep 600 && some_cmd &` and that will not block, it will keep running i... (1 comment)

2 answers

+12
−0

The traditional way on a *nix system to run a one-time command at some specified future time is at.

$ at 'now + 10 minutes'
at Wed Aug 23 19:00:00 2023
at> date >> ~/current-time
at> ^D
job NNN at Wed Aug 23 19:00:00 2023
$

You can also specify a particular time, which will be interpreted as "next time the real time is X":

$ at '16:00'
at Wed Aug 24 16:00:00 2023
...

or a date and time, although the syntax is a little peculiar:

$ at '22:00 Aug 29'
at Tue Aug 29 22:00:00 2023
...
$ at '22:00 Jul 29'
at Mon Jul 29 22:00:00 2024
...
$ at '22:00 Jul 29 2025'
at Tue Jul 29 22:00:00 2025
...

Normally, after the job finishes executing, any output (stdout or stderr) will be delivered in an email to the account which scheduled the job.

I do believe that most at implementations will start executing the job as soon as the specified time has occurred. So if the system is powered off, or atd otherwise isn't running, at the specified time, the job will execute the next time atd is started.

At least on a typical Debian system, it's also possible to pipe a command into at to schedule it; for example:

$ echo date | at 'now + 10 minutes'

will run date after approximately ten minutes.

To see which jobs are queued for execution, use atq. To see what a job will do when it is executed, use at -c $JOBID. To delete a job, use atrm $JOBID.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+11
−0

Using systemd timers is too much work? Not with systemd-run!

systemd-run --user --on-active=10min some_cmd
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »