Penguin

Differences between version 5 and predecessor to the previous major change of CronNotes.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 5 Last edited on Tuesday, June 29, 2004 8:50:33 am by AristotlePagaltzis Revert
Older page: version 1 Last edited on Monday, September 23, 2002 6:21:41 pm by CraigBox Revert
@@ -1,26 +1,37 @@
-Scheduling under Linux is provided by cron(8).  
+!!! Introduction  
  
-crontab -e as a user will edit the users crontab entry (which is hidden somewhere in /var/spool/cron .) You need to get the format right - read crontab(5) for the format of the entry
+Scheduling under Linux is provided by the cron (8) daemon . It reads a file called a crontab(5), but you don't necessarily need to edit any cron table directly
  
-The cron.d/cron.daily etc seem to vary slightly between distros. The basic guts of them are, put a script in /etc/cron.daily and the cron daemon will run it once a day ( at whatever time it runs that job - 3am or whenever 'midnight' maintenance is scheduled.)  
+!!! Running commands at standard intervals  
  
-These files are just normal shell scripts - no cron control info needed
+On most systems, the easiest thing you can do if you simply want your command to be run once an hour, or once a day, or once a week, etc, is to put a script in the corresponding one of the __/etc/ cron.{hourly,daily,weekly,monthly}__ etc directories. This is a simple [Shell] script, not a crontab(5) file. On most systems, all the "daily" scripts will be run sometime in the wee hours, such as 4am
  
-same for /etc/cron.{hourly,weekly,monthly}  
+!!! Running commands at custom times /intervals  
  
-/etc/cron.d has single-file crontab entries - these are crontab entries , so read crontab(5) again ;) . EG:  
+If you need to run commands at custom times or intervals , you need to know the crontab(5) line format described in the ManPage. Read that now, if you don't know about it yet
  
- # /etc/cron.d/exim: crontab fragment for exim  
+The main, system wide crontab(5) is __/etc/crontab__, but on most [LinuxDistribution]s, there is a __ /etc/cron.d__ directory where you should put single line crontab files, eg:  
  
+ # /etc/cron.d/exim: crontab fragment for exim  
  # Run queue every 15 minutes 
  08,23,38,53 * * * * mail if [[ -x /usr/sbin/exim -a -f /etc/exim/exim.conf ]; then /usr/sbin/exim -q ; fi 
  
-Every 15 minutes (8 past the hour, 23 past the hour etc) on every hour, every day, etc etc, as user mail, run the command ' if [[] ... fi'  
+This will be run every 15 minutes (8 past the hour, 23 past the hour etc) on every hour, every day, etc, as user mail. The initial fields are delimited by spaces , up to the the command (__ if [[] ... fi__), which is taken as a whole to the end of the line. (The __if__ bit is a sanity check to ensure a runnable exim binary and an __exim.conf__ file exist.)  
+  
+Users can also have their own cron tables, with commands run under their respective [UID]. These should be manipulated using the crontab(1) command. __crontab -e__ will launch your configured interactive TextEditor on your user crontab, which generally resides under __/var/spool/cron__.  
+  
+!!! Running commands at standard intervals, revisited, and more  
  
-The if magic is a sanity check - to check that its possible to run exim and there is an exim .conf file, before bothering to do anything else
+With Vixie Cron (used in [*BSD] and some [LinuxDistribution]s such as [Debian] and RedHat) you can use several special keywords instead of a time specification . This [FreeBSD 4 .1 manpage | http://www.freebsd.org/cgi/man.cgi?query=crontab&apropos=&sektion=5&manpath=FreeBSD+4.1-RELEASE&format=html], where this feature first appears, lists the following keywords:  
  
-/etc/crontab also has entries - the ones in my debian system tell cron to , every day, week , month, run the entries in /etc/cron .{daily, weekly,monthly} ,  
-respectively
+|^ string |^ meaning  
+| __@reboot__ | Run once , at startup.  
+| __@yearly__ | Run once a year , "0 0 1 1 *".  
+| __@annually__ | (sames as @yearly)  
+| __@monthly__ | Run once a month, "0 0 1 * *" .  
+| __@ weekly__ | Run once a week , "0 0 * * ".  
+| __@daily__ | Run once a day , "0 0 * * *".  
+| __@midnight__ | (same as @daily)  
+| __@hourly__ | Run once an hour, "0 * * * *"
  
-In short, the easiest thing for you to do, if you want your script run daily, is to drop it in /etc/cron.daily. if it needs custom runtimes , put  
-them in /etc/ cron.d/ in a crontab file
+__@reboot__ is particularly interesting , as cron will run such a command at system startup . This allows regular users to start their own daemons such as fetchmail(1) at boot time