The at command is used to run a task once, at a specified time. It is not designed for repetitive or regularly scheduled tasks. The at command is very flexible. Users can specify a particular date and time, or cause the scheduled command to run after a given period of time. The command is typically used in an interactive manner, where the at command and time interval are specified, then a task is defined in an interactive prompt. This enables the user to enter a path to a script or a command to be run. Pressing Ctrl+D exits the interactive mode.
Removing scheduled tasks
It’s nice to have the ability to schedule jobs to be run using the at utility. However, we need some form of control over the jobs scheduled. If we’ve decided to cancel a job, we can use the atrm command. The atrm command is used for canceling a job before it is executed by the at utility. For instance, we schedule a reboot using the at utility:
# at now + 5 minutes warning: commands will be executed using /bin/sh at> reboot at> [EOT] job 8 at Thu Sep 6 10:06:00 2018 # date Thu Sep 6 10:01:21 EDT 2018
Based on the preceding command, we have specified to reboot the system in five minutes using the at command. Now, if for some reason we want to cancel this job, we can use the atrm command. We can do this as follows:
# atq 4 Mon Sep 10 09:11:00 2018 a root 8 Thu Sep 6 10:06:00 2018 a root 7 Sun Sep 6 09:25:00 2043 a root # atrm 8 # atq 4 Mon Sep 10 09:11:00 2018 a root 7 Sun Sep 6 09:25:00 2043 a root
Based on the preceding command, we used the atq command to list the scheduled jobs; we then used the atrm command and specified the job ID to remove it.
atrm Command Examples
1. Remove job number 10:
# atrm 10
2. Remove many jobs, separated by spaces:
# atrm 15 17 22