Schedule jobs with at
The at command is used to execute a command once at a particular time. The time can be specified in two ways:
- time date – schedules the job to be run at that specific time. For example, 18:20 July 26 2015 will execute the command at that time.
- relative time from now – for example, now + 2 min will execute the command two minutes from now.
You can start the at program from the shell by typing the at command and the time specification. This will open up at a prompt where you can type in the command that will be run at the scheduled time. When you are done typing a command, press Ctrl+d to place the command in the queue and exit the prompt.
For example, to execute a command two minutes from now, we can use the following command:
You can display pending at jobs with the atq command:
To remove an at job from the queue, use the atrm command with the job number (the first number in the output of the atq command):
You can also pass a file with commands to the at command. This is done using the -f parameter. Consider the following example:
The job above will run commands from the file at_example.txt on July 26, 2015 at 18:37:
Note that the files from the /home/bob/tmp directory have been deleted. The events have been logged into the log.txt file.