Difference between revisions of "Crontab"


From Knoppix Documentation Wiki
Jump to: navigation, search
m (Reverted edits by 121.100.50.7 (Talk); changed back to last version by 78.143.200.245)
(Cleared up some misconceptions and misinformations)
 
Line 10: Line 10:
 
   
 
   
 
  crontab -l > crontabbackup.txt
 
  crontab -l > crontabbackup.txt
Another useful variation of the -l, list your crontab, allows you to send the schedule to a file.
+
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 verse MS Dos 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 '''/etc/crontab''' file.
+
Use this man command to read about the formatting requirements for your '''crontab''' files.
  
  
Note: Two classes of user will use this command. <br>
+
Note: there are two main types of crontab --
A user or the "root" user. Although, almost every Linux system, I've ran '''crontab -e''' as "root" '''does not''' support it. <br>
+
each user's crontab located in the directory /var/spool/cron/crontabs/''user'', and the main
In other words, if you are Sys Admin (root). Just '''vi /etc/crontab'''.
+
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 ==
 
== External links ==

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.

External links