[plug] Cron scheduling

Leon Brooks leonb at bounce.networx.net.au
Wed Oct 13 19:39:24 WST 1999


Paul Baumgarten wrote:
> OK... Time to ask something I have been curious about for a little while.

> I'm wanting to schedule jobs and I know the tool to use is Cron.  My problem
> is I have looked through all the Howtos and mini-howtos and can not find one
> for Cron.  I scanned through the man pages for Cron and Crontab but they
> don't explain very well how to create a scheduled job.  Can anyone point me
> to some useful documentation?

Make a file in your home directory called "crontab" and put the commands
you want to run in it, one per line. Now, on the front of each line add
five asterisks ('*') separated from each other and the command by
whitespace (one or more spaces or tabs).

At this point you have a local crontab which will run every job every
minute, which is probably not excatly what you want. Each * represents a
time field, and the fields are minute, hour, day of month, month of year
and day of week respectively. A * in the day-of-week field, for example,
means it's OK to run this line on every day of the week, and a * in the
minute field means it can run on any minute.

To run a task on minutes 0,15,30 and 45 of every hour, you might change
the first * into 0,15,30,45 - or, more simply, to */15 - read as "every
15th minute."

To pick a realish example, say you are running an ISP and wish to check
user logon duration every five minutes during the day, but couldn't care
less between 10PM and 7AM, nor on weekends. Imagine that your
user-checking script is called pitchoff.sh. The resulting crontab file
line would look like this...

*/5 8-21 * * mon-fri pitchoff.sh

..read as "every 5 minutes between the hours of 0800 through 2100 on
every day of the month and every month of the year but only on mondays
through fridays run pitchoff.sh". Try this with something harmless like
"echo case 1", and it will appear in your mailbox.

If pitchoff.sh produces output, you might like to add ">/dev/null
2>/dev/null" to the command to avoid being mailed _every_ time it is
run, but do give it a mechanism for reporting errors ('echo "help me obi
wan kenobi" | mail -s "I have a problem" $USER' works well).

To tell crontab that your file exists, issue the command "crontab
crontab". Be ready to type "crontab -r" if you don't get the results you
expect.

0 12 * * sun-fri echo "Time for lunch. It'll be here when you return"
0 17 * * sun-fri echo "Go home, work's finished, wife's waiting!"

Cheers


More information about the plug mailing list