Skip to main content
p. 186

7.7 Scheduling One-Time Tasks with at

To run a job once in the future without using cron, use the at service. For example, to run myjob at 10:30 PM, enter this command:

$ at 22:30
at> myjob

End the input with CTRL-D. (The at utility reads the commands from the standard input.)

p. 188

To check that the job has been scheduled, use atq. To remove it, use atrm. You can also schedule jobs days into the future by adding the date in DD.MM.YY format—for example, at 22:30 30.09.15.

There isn’t much else to the at command. Though it isn’t used that often, it can be invaluable when the need does arise.

7.7.1 Timer Unit Equivalents​

You can use systemd timer units as a substitute for at. These are much easier to create than the periodic timer units that you saw earlier, and can be run on the command line like this:

# systemd-run --on-calendar='2022-08-14 18:00' /bin/echo this is a test
Running timer as unit: run-rbd000cc6ee6f45b69cb87ca0839c12de.timer
Will run service as unit: run-rbd000cc6ee6f45b69cb87ca0839c12de.service

The systemd-run command creates a transient timer unit that you can view with the usual systemctl list-timers command. If you don’t care about a specific time, you can specify a time offset instead with --on-active (for example, --on-active=30m for 30 minutes in the future).

note

When using --on-calendar, it’s important that you include a (future) calendar date as well as the time. Otherwise, the timer and service units will remain, with the timer running the service every day at the specified time, much as it would if you created a normal timer unit as described earlier. The syntax for this option is the same as the OnCalendar option in timer units.