Hardware Reference
In-Depth Information
There is also a -u option that allows root to edit the crontab of other users. A typical file might begin with the following:
# m h dom mon dow command
00 7 * * 1-5 /usr/local/minerva/etc/alarm 1
10,15 7 * * 1-5 /usr/local/minerva/etc/alarm 2
*/5 * * * * /usr/local/bin/getmail --quiet
The # line is a comment and acts as a reminder of the columns; minutes, hours, day of month (from 1 to 31),
month (1 to 12, or named by abbreviation), day of week (0 to 7, with Sunday being both 0 and 7), and the command
to be executed. Each column supports the use of wildcards (* means any), inclusive ranges (1-5), comma-delimited
sequences (occurring at 10 and 15 only), and periodic ( */5 indicates every five minutes in this example). The cron
program will invoke the command if, and only if, all conditions can be met.
Typical uses might be as follows:
u
An alarm clock, triggering messages, weather reports, or news when waking up
u
Retrieving e-mail for one or more accounts, at different rates
u
Initiating backups of local data, e-mail, or projects
u
Controlling lights while on holiday
u
Controlling lights to switch on, gradually, when waking up
u
Real-life reminders for birthdays, anniversaries, Mother's Day, and so on
Because these occur under the auspices of the user (that is, owner) of the crontab, suitably permissions must
exist for the commands in question.
N Many users try to avoid running anything as root, if it is at all possible. Therefore, when adding timed tasks
to your home, it is recommended you add them to the crontab for a special myhouse user and assign it only the specific
rights it needs.
Note
The crontab, as provided, is accurate to within one minute. If you're one of the very few people who need
per-second accuracy, then there are two ways of doing it. Both involve triggering the event on the preceding minute
and waiting for the required number of seconds. The first variation involves changing the crontab to read as follows:
00 7 * * 1-5 sleep 30; /usr/local/minerva/etc/alarm 1
The second involves adding the same sleep instruction to the command that's run. This can be useful when
controlling light switches in a humanistic way, as it is rare to take exactly 60 seconds to climb the stairs before turning
the upstairs light on.
For randomized timing, you can sleep for a random amount of time ( sleep `echo $((RANDOM%60))s` ) before
continuing with the command, as you saw in Chapter 1.
There will also be occasions when you want to ignore the cron jobs for a short while, such as disabling the alarm
clock while we're on holiday. You can always comment out the lines in the crontab to do this or change the command
from this:
/usr/local/minerva/etc/alarm 1
 
Search WWH ::




Custom Search