GNU/Linux Command-Line Tools Summary
Prev
Next
Chapter 18. Scheduling Commands to run in the background
There are two main tools used to perform scheduled tasks, at and cron . You may also like to try anacron if your computer does not run continuously, as cron will only work if your computer is left on (anacron can catch up with the scheduled tasks the next time the computer is on...).
- at
- atq
- atrm
- cron
- crontab
-e --- to edit the file.
-l --- to list the contents of the file.
-u username --- use the -u with a username argument to work with another users crontab file.
@reboot --- run command at reboot
@yearly --- same as 0 0 1 1 *
@annually --- same as @yearly
@monthly --- same as 0 0 1 * *
@weekly --- same as 0 0 * * 0
@daily --- same as 0 0 * * *
@midnight ---
'at' executes a command once on a particular day, at a particular time. at will add a particular command to be executed.
Examples:
at 21:30
You then type the commands you want executed then press the end-of-file key (normally CTRL -D ). Also try:
at now + time
This will run at the current time + the hours/mins/seconds you specify (use at now + 1 hour to have command(s) run in 1 hour from now...)
You can also use the -f option to have at execute a particular file (a shell script).
at -f shell_script now + 1 hour
This would run the shell script 1 hour from now.
Will list jobs currently in queue for the user who executed it, if root executes at it will list all jobs in queue for the at daemon. Doesn't need or take any options.
Will remove a job from the 'at' queue.
Command syntax:
atrm job_no
Will delete the job "job_no" (use atq to find out the number of the job)
cron can be used to schedule a particular function to occur every minute, hour, day, week, or month.
It's normal to use the crontab to perform the editing functions as this automates the process for the cron daemon and makes it easier for normal users to use cron.
Anacron
anacron is another tool designed for systems which are not always on, such as home computers
While cron will not run if the computer is off, anacron will simply run the command when the computer is next on (it catches up with things).
crontab is used to edit, read and remove the files which the cron daemon reads.
Options for crontab (use crontab -option(s) ):
When using crontab -e you have a number of fields (6) what they mean is listed below:
Field
Allowed Values
minute
0-59
hour
0-23
day of month
1-31
month
1-12 (or names, see below)
day of week
0-7 (0 or 7 is Sun, or use three letter names)
There are also a number of shortcut methods for common tasks, including:Prev
* License

