[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
howtos:general_admin:task_scheduling [2013/01/06 19:18 (UTC)] – added reviewed flag mfillpot | howtos:general_admin:task_scheduling [2015/06/24 19:25 (UTC)] – tdrssb | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <!-- Reviewed 2013-01-06 mfillpot --> | + | <!-- Reviewed 2013-10-16 mfillpot --> |
<!-- Add your text below. We strongly advise to start with a Headline (see button bar above). --> | <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). --> | ||
====== Task Scheduling in Linux ====== | ====== Task Scheduling in Linux ====== | ||
=====Overview===== | =====Overview===== | ||
- | This article discusses some tools used in a Linux system to schedule tasks to run automatically at specified time intervals or at any given point of time in the future. | + | This article discusses some tools used in a Linux system to schedule tasks to run automatically at specified time intervals or at any given point of time in the future. |
Some task-scheduling daemons used in Linux/UNIX are: | Some task-scheduling daemons used in Linux/UNIX are: | ||
* '' | * '' | ||
- | < | + | * '' |
- | commonly used --> | + | * '' |
- | * '' | + | |
- | < | + | =====Using at===== |
- | periodic scheduler that doesn' | + | The **//at//** command allows a user to execute commands or scripts at a specified time (required) and date (optional). The commands can be entered via standard input, redirection, |
- | | + | |
+ | < | ||
+ | darkstar:~% at | ||
+ | </ | ||
+ | |||
+ | =====Interactive at===== | ||
+ | Using the command **//at//** with standard input (keyboard) is a little more complicated than typing one line in at the prompt. The command uses an internal "sub-shell" to gather the required information. Once the command information entry is complete, < | ||
+ | |||
+ | < | ||
+ | darkstar:~% at 12:01 -m | ||
+ | warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh | ||
+ | at> ./ | ||
+ | at> < | ||
+ | job 4 at 2015-06-22 12:01 | ||
+ | darkstar:~% | ||
+ | </ | ||
+ | |||
+ | =====File-driven at===== | ||
+ | Commands can also be contained within a file and run by **// | ||
+ | < | ||
+ | darkstar:~% at 12:32 -m -f / | ||
+ | warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh | ||
+ | job 8 at 2015-06-22 12:10 | ||
+ | </ | ||
+ | The **-m** flag will email the user after completion of the command; the **-f** flag specifies the command will read the job from a file, not from standard input. After the command is typed in (and the appropriate warning is displayed), the **//at//** job number((As distinct from a process ID (PID) known to the operating system)) is displayed. | ||
+ | |||
+ | =====at Internal Scheduling===== | ||
+ | The job numbers provided after a command is typed in, or when a file is read, allow the user to know which internal job will be run in sequential order. If a user wants to delete a specific task, all that needs to be known is this internal job number. To remove the job, the command **// | ||
+ | |||
+ | < | ||
+ | darkstar: | ||
+ | 7 2015-06-22 12:10 p tux | ||
+ | 8 2015-06-22 12:15 p root | ||
+ | </ | ||
+ | |||
+ | The command **//atq//** (**__at__ __q__ueue**) is the same as **//at -l//**: | ||
+ | |||
+ | < | ||
+ | darkstar: | ||
+ | 7 2015-06-22 12:10 p tux | ||
+ | 8 2015-06-22 12:15 p root | ||
+ | </ | ||
+ | |||
+ | To remove the user job, use **// | ||
+ | < | ||
+ | darkstar: | ||
+ | </ | ||
+ | |||
+ | =====Using cron===== | ||
+ | |||
+ | **// | ||
+ | |||
+ | **// | ||
+ | |||
+ | < | ||
+ | darkstar:~% crontab -e | ||
+ | </ | ||
+ | |||
+ | To edit the system-level // | ||
+ | |||
+ | < | ||
+ | darkstar:~# crontab -e | ||
+ | </ | ||
+ | |||
+ | If your system has **// | ||
+ | |||
+ | < | ||
+ | darkstar:~% sudo crontab -e | ||
+ | </ | ||
+ | |||
+ | The //crontab// file syntax is: | ||
+ | |||
+ | < | ||
+ | # * * * * * command to execute | ||
+ | # │ │ │ │ │ | ||
+ | # │ │ │ │ │ | ||
+ | # │ │ │ │ └───── day of week (0 - 6) (Sun(0) /Mon (1)/Tue (2)/Wed (3)/Thu (4)/Fri (5)/Sat (6)) | ||
+ | # │ │ │ └────────── month (1 - 12) | ||
+ | # │ │ └─────────────── day of month (1 - 31) | ||
+ | # │ └──────────────────── hour (0 - 23) | ||
+ | # └───────────────────────── min (0 - 59) | ||
+ | </ | ||
+ | |||
+ | Using an asterisk in any placeholder location, will match any value. For example, the following will run // | ||
+ | |||
+ | < | ||
+ | #For more information see the manual pages of crontab(5) and cron(8) | ||
+ | # | ||
+ | # min hr day month weekday command | ||
+ | # | ||
+ | # | ||
+ | |||
+ | 0 11 * 1-3 * / | ||
+ | </ | ||
+ | |||
+ | =====Using anacron===== | ||
+ | < | ||
+ | **// | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | The links in red are to non-existent articles. | ||
+ | |||
+ | If you are experienced with those tools, please feel free to write the articles. | ||
+ | </ | ||
====== Sources ====== | ====== Sources ====== | ||
Line 18: | Line 125: | ||
<!-- Authors are allowed to give credit to themselves! --> | <!-- Authors are allowed to give credit to themselves! --> | ||
* Originally written by [[wiki: | * Originally written by [[wiki: | ||
- | * Contrbutions by [[wiki: | + | * Contrbutions by [[wiki: |
+ | * Example crontab example modified from [[en.wikipedia.org/ | ||
<!-- Please do not modify anything below, except adding new tags.--> | <!-- Please do not modify anything below, except adding new tags.--> | ||
<!-- You must also remove the tag-word " | <!-- You must also remove the tag-word " | ||
{{tag> | {{tag> | ||