Difference between revisions of "Crontab"
(Init from PHPWiki) |
Polymath69 (Talk | contribs) (Cleared up some misconceptions and misinformations) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 4: | Line 4: | ||
crontab -e | crontab -e | ||
− | To edit your crontab file. | + | To edit your crontab file. |
crontab -l | crontab -l | ||
Line 10: | Line 10: | ||
crontab -l > crontabbackup.txt | crontab -l > crontabbackup.txt | ||
− | Another | + | Another use of the -l switch allows you to send the schedule to a file. |
crontab crontabbackup.txt | crontab crontabbackup.txt | ||
− | If you use the crontab -l option and send the output to a file as was shown in the prior command example, you can take that schedule and import it into another schedule. All you have to do is use [[crontab]] and supply your backed up schedule file. This is a great trick for [[knoppix]]. The creative use of this format of the command would be import your schedule from a [[USB]] thumb drive or a hard drive partion. You could even store the file on a MS Windows partition as long as the file is in [[linux]] format | + | If you use the crontab -l option and send the output to a file as was shown in the prior command example, you can take that schedule and import it into another schedule. All you have to do is use [[crontab]] and supply your backed up schedule file. This is a great trick for [[knoppix]]. The creative use of this format of the command would be to import your schedule from a [[USB]] thumb drive or a hard drive partion. You could even store the file on a MS Windows partition as long as the file is in [[linux]] format versus MS-DOS format. |
man 5 crontab | man 5 crontab | ||
− | Use this man command read about the formatting requirements for your ''' | + | Use this man command to read about the formatting requirements for your '''crontab''' files. |
− | Note: | + | Note: there are two main types of crontab -- |
− | + | each user's crontab located in the directory /var/spool/cron/crontabs/''user'', and the main | |
− | + | system crontab '''/etc/crontab'''. | |
+ | The '''crontab -e''' command will edit only the | ||
+ | per-user crontab files. Use '''sudo vi /etc/crontab''' | ||
+ | to edit the systemwide crontab, but use this with | ||
+ | caution or as a last resort as this command will | ||
+ | bypass the syntax checking enforced by '''crontab -e'''. | ||
+ | |||
+ | == External links == | ||
+ | * [http://www.math-linux.com/spip.php?article45 Crontab : Scheduling Tasks] | ||
+ | [[Category:Useful Linux Commands]] | ||
+ | |||
+ | * [http://www.hxpi.com/cron_sandbox.php A safe place to experiment with crontab commands is Cron Sandbox at HxPI where you can see straightaway a future schedule of run times for whatever crontab parameters you type in.] |
Latest revision as of 11:20, 6 September 2009
Scheduling jobs on linux requires two parts. The first part is having the crond daemon running. The second part is using the crontab command to create a schedule. The schedule is a list of jobs with times that you'd like to have run.
There are two versions of the command that you will use most of the time.
crontab -e
To edit your crontab file.
crontab -l
To list your crontab file.
crontab -l > crontabbackup.txt
Another use of the -l switch allows you to send the schedule to a file.
crontab crontabbackup.txt
If you use the crontab -l option and send the output to a file as was shown in the prior command example, you can take that schedule and import it into another schedule. All you have to do is use crontab and supply your backed up schedule file. This is a great trick for knoppix. The creative use of this format of the command would be to import your schedule from a USB thumb drive or a hard drive partion. You could even store the file on a MS Windows partition as long as the file is in linux format versus MS-DOS format.
man 5 crontab
Use this man command to read about the formatting requirements for your crontab files.
Note: there are two main types of crontab --
each user's crontab located in the directory /var/spool/cron/crontabs/user, and the main
system crontab /etc/crontab.
The crontab -e command will edit only the
per-user crontab files. Use sudo vi /etc/crontab
to edit the systemwide crontab, but use this with
caution or as a last resort as this command will
bypass the syntax checking enforced by crontab -e.