[plug] Crontab??

Cameron Patrick cameron at patrick.wattle.id.au
Tue Jul 27 19:54:33 WST 2004


Senectus . wrote:

> I have various jobs that I want to start and stop at particular times.
> I've tried all sorts of things but I've never seem to be able to get
> crontab to do what I want it to do, when I want it...
> I've read man files (not much use), and various howto's etc.. and none
> of them seem to make any sense.. does anyone know of a decent tutorial
> for crontab?

It's dead easy once you see it done so I'll give a couple of examples
which may make the man pages easier to follow.

There are actually two types of crontab files, one for normal users
(which users can edit themselves) and one for the whole system (which
will let you run stuff as any user).  The system-wide one lives in
/etc/crontab; the per-user ones are edited by the crontab command:

	$ crontab my.crontab    <-- install my.crontab as my per-user crontab
	$ crontab -e            <-- open an editor with my crontab file
	$ crontab -l		<-- list the contents of my crontab

The format of the crontab files is described in crontab(5).  Basically
you list one job on each line, preceded by several fields saying when
you want it to run.  Here are some examples:

#min	hr      day     month	dayofweek
45      21      *       *       *       /home/cameron/bin/backup-xbox-to-euclid
This one runs the mentioned shell script at 9:45 every night.

00      21      *       *       fri     some-script
This one runs at 9pm on Friday nights.

*/2     *       *       *       *       some-script
This one runs every two minutes.

The per-user crontab files live somewhere in var so to edit them you
*have* to go through the crontab command.  The system-wide
/etc/crontab can be edited like any file.  The format is similar but
it also has a column for which user to run the command as.  Examples:

0,30 *     * * *   root    script-to-run-every-half-hour
20   18    * * *   root    script-to-run-at-6:20pm-every-day
20   18    * * 6   root    script-to-run-on-saturdays
20   18    1 * *   root    script-to-run-on-the-first-of-each-month

Cameron.



More information about the plug mailing list