Talk:Crontab
From Gentoo Linux Wiki
Contents |
[edit] Using CRON as a notifier
I want CRON to give me a warning for recurring vital events. What commands could be used in CRONTAB.
A first command to try is
wall 'Coffee!'
But this only works if you have a terminal open, which is not always the case.
So if you are in X try
env DISPLAY=:0 xmessage 'Coffee!'
This is ugly. If you want something more fancy, emerge xosd. If you are not interested in osd-support for xmms, use
USE="-xmms" emerge xosd
to prevent unnecessary dependencies from being emerged as well. Adding
x11-libs/xosd -xmms
to /etc/portage/package.use will preclude the unneccessary dependencies from sneaking in when emerge is called with -uD world.
Now we can use something like
echo 'Coffee!' | env DISPLAY=:0 osd_cat -p middle -A centre
Read through
man osd_cat
to see the options you can use to make this more fancy and run
xfontsel
to select the desired font (to be used with the -f option of osd_cat).
Someone suggested
echo 'Coffee!' > /dev/speech
which might be ideal for you... not for me.
[edit] How to change when updatedb runs
The program updatedb, which updates the database for slocate, is normally set to run once a day at midnight. If you're usually up late, this may be an inconvenient time to saturate your disk bandwidth.
[edit] Changing the interval that updatedb runs
If you want to change the interval, not the time of day, that updatedb runs, simply move the slocate script to the appropriate directory. For example:
mv /etc/cron.daily/slocate /etc/cron.weekly
or
mv /etc/cron.daily/slocate /etc/cron.monthly
[edit] Changing the time of day updatedb runs
There are two ways to change the time of day that updatedb runs. One way is to change the time that the 'touch file' is deleted.
This has the side effect of altering the time that all scripts in /etc/cron.daily are run.
Open /etc/crontab in your editor.
nano -w /etc/crontab
Find the line that deletes the touch file. It looks like this
0 0 * * * root rm -f /var/spool/cron/lastrun/cron.daily
Change the time, where the first number is the minute, and the second is the hour. To run updatedb (and all of the daily jobs) at 4:30 AM use this:
30 4 * * * root rm -f /var/spool/cron/lastrun/cron.daily
Save the file, and you're done.
The other way of changing the time of day has fewer side effects, allowing other scripts to run at midnight as before. First, move the slocate script so that run-crons doesn't find it.
mv /etc/cron.daily/slocate /root
Next, add an entry to /etc/crontab
30 4 * * * root /root/slocate
Save the file, and you're done.
[edit] Esoterics
Here's a quick summary of how updatedb and the other cron.hourly|daily|weekly|monthly scripts are processed.
There are two conditions under which updatedb runs. One is when the touch file, /var/spool/cron/lastrun/cron.daily is deleted. The touch file is normally deleted by cron every midnight, as specified in the file /etc/crontab. The cron program also calls /usr/sbin/run-crons every fifteen minutes, also determined by a line in /etc/crontab. The run-crons script looks for the touch file. If the touch file does not exist, run-crons runs every script found in the /etc/cron.daily/ directory. One of the scripts, /etc/cron.daily/slocate is a simple script to call updatedb. Finally, run-crons re-creates the touch file.
The other condition is normally triggered only because the machine was off at midnight. Within fifteen minutes of startup, the run-crons script is called. When run-crons notices that the touch file is older than one day and five minutes, it deletes the touch file. Later parts of the same script behave as above. Noticing that the touch file does not exist, the /etc/cron.daily scripts are all run, and the touch file is re-created.
