Unix systems including Linux have a mechanism that automatically can execute programs at a specified time – for instance daily at a certain time of day or weekly or monthly at a given day and here again at a certain time of day. All of this is triggered by a file named crontab which usually resides in the directory /etc (i. e., /etc/crontab) and contains the particular indications.
Unix workstations, on which this mechanism has been introduced initially, used to operate continuously 24 hours a day. Therefore, the crontab triggering takes effect only exactly at the specified point in time. If the computer is not operating at this time, the item decays and the program in question will not be started.
Linux PCs often are operating non-continuously. What is needed here is a procedure where the crontab trigger is reinserted at a later point in time, in case the PC was off at the actually configured time. Programs whose execution by crontab has been missed at the proper time should be started later on as soon as the PC is operating again.
There are alternative solutions for this like anacron, but apparently these do not fit quitely into current systems' topography. OpenSUSE uses another approach: /etc/crontab contains an item that runs the program /usr/lib/cron/run-crons in short intervals (every 15 minutes). This in turn looks for program scripts in the directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly, which it starts when at least 60 minutes, 24 hours, 7 days or 30 days have been gone by since the last run, respectively.
In this way, one can put up programs into the concerning /etc/cron.* directories that shall be executed in regular time intervals. Though, for the system administrator it might not be the best choice to touch these system directories. For this reason, under OpenSUSE by default there is a script like suse.de-cron-local in the directory /etc/cron.daily that in turn calls the script /root/bin/cron.daily.local (if that exists). Hence, the administrator is able to define tasks to be executed daily by his own /root/bin directory.
Unfortunately, there are no corresponding scripts for hourly, weekly or monthly intervals by default. However, suse.de-cron-local can be enhanced so that it is applicable universally in the sense mentioned. In the attachment below I provide a shell script cron-local that realises such an enhancement.
After downloading and unpacking of cron-local.gz just copy or link cron-local into the directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly (as required); also, don't forget to make the respective file executable. (Either skip /etc/cron.daily or delete the default script suse.de-cron-local or the like – if existent – to avoid multiple executions!)
After that, the administrator can set up scripts cron.hourly.local, cron.daily.local, cron.weekly.local or cron.monthly.local (according to the directories chosen above) in his /root/bin directory which then will be executed in the appropriate time intervals. Of course, all of these are still optionally: if a file is absent, this simply will be ignored.
Attachment | Size |
---|---|
cron-local.gz | 458 bytes |