If you look at '/etc/crontab', the control file for
the cron scheduling daemon, you will notice that by default all daily, weekly
and monthly system tasks are run between 4 and 5 o'clock in the morning.
If your computer isn't turned on during this time, the cron jobs won't be
executed.
One solution to this problem would be changing the hour fields to a time
when your system is most likely running (I used to change them to 2 pm.).
Another solution would be running the 'anacron'system service.
First you should make sure that 'anacron' is up and
running, either via the Mandrake Control Center (System - Services), or by
making a shortcut via the command line (as 'root'):
# chkconfig --list anacron
to check and
# chkconfig anacron on
to enable the service.
Note that 'anacron' isn't meant as a replacement for
'cron', it's an add-on.
'anacron', the 'anachronistic command scheduler', uses
relative time scales ('once a day / week / month') instead of absolute time
scales ('4:15am, Feb 15'). So, even if you 'miss' a particular time or date
for which a job is scheduled, it will be executed shortly after you've booted
the system. It works like this:
- 'anacron' looks up the 'timestamps' for its jobs
in '/var/spool/anacron'.
- If according to a time stamp a job is due, 'anacron'
will run it.
- 'anacron' updates the time stamp for the job.
'anacron' is controlled by the file '/etc/anacrontab'.
If you open it in a pager, you will see that the preconfigured Mandrake Linux
cron jobs are already entered in there:
1 5 cron.daily run-parts /etc/cron.daily
7 10 cron.weekly run-parts /etc/cron.weekly
30 15 cron.monthly run-parts /etc/cron.monthly
- The first field denotes the period in days:
1
is daily, 7 every 7 days (weekly) etc.
- The second field denotes the delay for jobs to be
executed after anacron has started in minutes. So,
5 says 'run
scheduled jobs 5 minutes after start'. This mechanism prevents queued jobs
from being run all at the same time.
- The third field contains an identifier. 'anacron'
uses this identifier for its timestamps and in messages.
- The fourth field finally lists the command to execute.
Caveats And Limitations
'anacron' does not replace 'cron' because due to its
very nature, it can't execute minutely or hourly scheduled jobs. It doesn't
provide a mechanism for running jobs under different users, i.e. all jobs
are run as 'root'.
Example: Getting Your New Mail After Boot
You want your computer to get your new mail after having
booted it in the morning. Since you boot your machine at different times,
a cron job won't do.
You need a properly configured
mail daemon, a mail retrieving utility like Fetchmail and a scripted dial-up connection.
Add this command (one line) to '/etc/anacrontab':
1 3 getmail pppd call ISP && fetchmail
-s && killall pppd
Since 'anacron' executes all commands as 'root', the
'.fetchmailrc' file must have the permissions-rw------- root root
set and should ideally reside in 'root's' home directory. Another possibility
would be putting the commands into a script and putting su user
before the line which starts 'fetchmail'.
section index top
'at', 'cron' and 'anacron' do not allow to start programs
which require user input, like X applications. This is because they don't
have a shell to start a program from. 'sleep' can do that, but only within
a session.
Surprisingly enough there seems to be only one program
currently which saves schedules to a file and thus allows to launch arbitrary
interactive programs at a given time. This program is called 'rclock' and
is part of the 'rxvt' package. If you find others, you are invited to tell
me ;).
section index top
|