[Sussex] Regular scheduled jobs?

Richie Jarvis richie at helkit.com
Fri Apr 1 10:50:42 UTC 2005


John D. wrote:
> I suspect that I was getting rather lost, because it went off into
> technospeak at quite an early stage - and not being able to find
> anything on the system that remotely resembled what the howto was
> talking about, threw me somewhat!
Hi John,

Firstly, forget about anacron and vixie-cron - they are not what you 
want to achieve, they simply execute missed jobs when the machine wasn't 
turned on, or cron wasn't running.

For a first cut in cron land, try this:

The command you want is crontab.  It has 2 (important) options: -l and -e

crontab -l will list the contents of that users crontab.  Cron maintains 
a different schedule list for each user, and therefore what you see in 
the crontab -l listing for one user will be different to another.  Here 
is one of my machines root user crontab:

Example of crontab -l:

-bash-2.05b# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.4593 installed on Tue Oct 26 12:56:21 2004)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
00 20 * * * /data/dbbackups/mysql/windward-backup-script.sh

The above crontab shows 1 job - the other lines prefixed by # are 
comments.

crontab -e simply starts your chosen editor (usually vi) in the crontab 
file, which allows you to enter new jobs and modify or delete existing 
jobs.  Each job must be on one line in the crontab file.

There are 6 fields in the cron job shown above, separated by a space 
character:

position 	field          	allowed values
--------	-----          	--------------
1		minute         	0-59
2		hour           	0-23
3		day of month   	1-31
4		month          	1-12 (or names, see below)
5		day of week    	0-7 (0 or 7 is Sun, or use names)
6		command	 	the command or script you wish to run

So, to make cron dump the output from dmesg to file at at 03:35 on every 
tuesday, I would enter the following into the crontab file:

35 03 * * 2 dmesg > /var/log/dmesgoutput

The * values mean that the day of month and month values are to be ignored.

To confirm that cron has done its job, check the /var/log/cron file (on 
FC3 systems - may be different on Gentoo) This file shows an entry each 
time cron executes a job, or crontab is used to list or edit the job list.

Example of /var/log/cron from an FC3 system:

Apr  1 11:30:00 windward CROND[3563]: (apache) CMD (php 
/var/www/html/cacti/cmd.php > /var/log/cacti.log 2> /dev/null)
Apr  1 11:30:00 windward CROND[3564]: (root) CMD (/usr/lib/sa/sa1 1 1)
Apr  1 11:35:00 windward CROND[5309]: (apache) CMD (php 
/var/www/html/cacti/cmd.php > /var/log/cacti.log 2> /dev/null)
Apr  1 11:35:12 windward crontab[5405]: (cc) LIST (cc)
Apr  1 11:35:19 windward crontab[5455]: (richie) LIST (richie)
Apr  1 11:35:27 windward crontab[5544]: (root) LIST (root)
Apr  1 11:40:00 windward CROND[7086]: (apache) CMD (php 
/var/www/html/cacti/cmd.php > /var/log/cacti.log 2> /dev/null)
Apr  1 11:40:00 windward CROND[7087]: (root) CMD (/usr/lib/sa/sa1 1 1)

Anyway, that is a quick intro to cron.  You can do other funky things, 
like making cron execute a job every X minutes, or hours.  And also you 
can make cron mail different users, or discard the output.  The 
possibilities are (almost) endless.

The next part of your task once you have got to grips with cron (from 
what you said to me last night) is to find a command to dump a colour 
print job to a printer.  I must admit I am not sure what to advise on 
that score.  Personally, I would probably make test page, and then write 
the postscript to file, and then write that file directly to the printer 
port - whether that will work or not, I don't know (never tried it!), 
but that would be my first port of call.

Cheers,

Richie





More information about the Sussex mailing list