Scheduling Programs I
Summary:- What Scheduling Can Do
- 'sleep', 'at', 'cron' and 'anacron'
- 'sleep'
- 'at'
What Scheduling Can Do
You are sitting at your new Linux machine, happily typing away (or grudgingly trying to solve some weird problem ;)), when all of a sudden your hard disk spins up and your system shows all signs of some lively activity going on. After a few minutes, the activity trails off and everything is as it was. You have just encountered your first scheduled 'job'. Job is Unix slang for a program running in the 'background', i.e. without requiring user intervention. Mandrakelinux comes with several preconfigured schedules which take care of system maintenance: updating the data bank for the 'locate' command, moving the logging files in '/var/log' ('rotating' them), running security checks, removing unused modules from system memory etc. If you are curious, have a look at the directories '/etc/cron.d/' (minute scheduled jobs), '/etc/cron.hourly/' (hourly scheduled jobs), '/etc/cron.daily/' and '/etc/cron.monthly/' which contain the scripts executed by the (ana)cron daemon via '/etc/crontab'. Of course you can also take advantage of this system, e.g. for- running regular backups,
- letting the system dial-up and retrieve mail every hour,
- sending yourself reminder messages,
- sending out birthday emails to the right person at the right date,
- removing temporary or unused files,
- scheduling downloads, uploads, mirroring,
- logging off idle users etc. etc.
'sleep', 'at', 'cron' and 'anacron'
These four are responsible for delayed and scheduled command execution:- sleep suspends a running job for a given period of time.
- at starts a job at a certain time.
- cron runs jobs in fixed intervals.
- anacron runs jobs in flexible intervals.
'sleep'
Unless you are writing your own scripts (or are editing others), 'sleep' won't be of much use to you. In scripts, however, it plays a quite prominent role. Its syntax is sleep seconds If you've ever watched the boot messages o an Mandrake Linux system closely, you will have noted the message Press 'I' to enter interactive startup. Have you ever managed to press the 'I' key fast enough? Well, I didn't. So I opened the file '/etc/rc.d/rc.sysinit' as 'root' in an editor. I foundif { "$PROMPT" 1.1 = "no" }; then gprintf "\t\tPress 'I' to enter interactive startup." echo -en "\r" echo sleep 1 fi
sleep 1
sleep 5
Example: Pop-up Reminder
You have ten minutes left before you have to leave your computer. You want Linux to tell you when these ten minutes are over.This either requires 'xmessage' (part of the 'X11R6-contrib' package) or 'gmessage' (part of the 'gtkdialogs' package). Enter this command into a virtual terminal (or the pop up command line of your window manager): (sleep 10m; gmessage "Time to leave") & This will pop up a message box on your desktop in ten minutes. section index
'at'
'at' adds scheduled jobs to the persistent 'at queue', managed by 'atd', the 'at daemon'. 'atd' must run for 'at' to work properly. You can check that as 'root' with ~# service atd status You can provide 'at' with absolute times, like 'April 30, 12.00' (at 1200 Apr 30), or with relative times like 'Tomorrow, 2.00 PM' (at 2pm tomorrow) or even 'In 5 hours, 25 minutes from now' (e.g. if it's 4 o'clock in the afternoon: at 0425pm + 5 hours). Valid time options are listed in '/usr/share/doc/at-{...}/timespec'. Adding a job to the 'at queue' follows a somewhat peculiar scheme. You type in the time and - optionally - date first, hitat> command_1
at> command_2
at> ~~
~~warning: commands will be executed using /bin/sh
job number at full time and date If the scheduled commands produce any output, 'at' will mail it to you.
To get a list of your queued 'at' jobs, run atq, to remove a job from the queue, use atrm job.
Example: Sending yourself a scheduled reminder message
You have to make an important phone call in three days from now on at 4 pm. In order to be reminded of that, tell 'at' to send you a message half an hour before (your mail daemon must be configured properly for this to work): at 0330pm today + 3 daysat> echo "remember call at 41.1 " | mail your_username@localhost
at>
Administrativa
The 'batch' tool is part of the 'at' package. 'at' jobs invoked by 'batch' are only executed when the system load is below 0.8 (this value can be adjusted with the atd -l value command).The default configuration allows all users to use 'at'. To exclude users, add their login names to '/etc/at.deny' (or add all privileged users to '/etc/at.allow'). section index Next Item: 'cron', for doing the same things again and again and again ...
Related Resources:
info sleepman at
~MdkR ef I.4.4 Revision / Modified: Jan. 02, 2002 / Jan. 28, 2002
Author: Tom Berger Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.
Scheduling Programs I
Version 1.4 last modified by esfa on 21/12/2004 at 13:51
Version 1.4 last modified by esfa on 21/12/2004 at 13:51
Document data
- Lost account?
- Join the community, be part of the Club: it's free!
- Get the PWP Download Subscription!
Mandriva.com
Store
Club


