Introduction
Related Files
Commands
The commands in this section are all used to tell the system to do something at (or until) a later time.
Proper use of these commands is the key to an
· system security checks (passwords, file access…)
· cleanup of temporary files (rm /tmp/*)
· updating system databases (updatedb)
·
The following commands are included in this section:
|
at |
Add a job to the scheduling queue. |
|
atq |
Display the contents of the scheduling queue. |
|
atrm |
Remove a job from the scheduling queue. |
|
batch |
Execute queue only when system resources permit. |
|
crontab |
Maintain schedule of jobs to be executed. |
|
sleep |
Wait some number of seconds. |
|
usleep |
Wait some number of microseconds. |
|
/var/spool/at |
List of at commands to be spooled. |
|
/var/spool/at/spool |
Spooled at commands. |
|
/proc/loadavg |
Contains system load average. |
|
/var/run/utmp |
Displays the database of users currently logged in. |
|
/etc/at.allow |
Users permitted to use "at". |
|
/etc/at.deny |
Users
|
|
/etc/cron.allow |
Users permitted to use "cron". |
|
/etc/cron.deny |
Users prohibited from using "cron". |
at
[-V] [-q queue ] [-f file] [-mldbv] TIME
at
-c job [ job… ]
atq
[-V] [-q queue ] [-v]
atrm
[-V] job [ job… ]
batch
[-V] [-q queue ] [-f file ] [-mv] [TIME]
The at command suite ( at, atq, atrm, batch ) is a utility for executing commands at a later time. More than one command may be scheduled for execution at a time. A set of scheduled commands is called a queue.
|
at |
Execute commands at a specified time. |
|
atq |
List the current
|
|
atrm |
Delete jobs from the queue. |
|
batch |
Run only the commands when the system load levels permit. |
Specifying a Time
There are three ways to specify a time: Absolute, Relative, or Verbal.
|
Absolute: |
MM/DD/YY or DD.MM.YY or MMDDYY (with or without HH:MM) |
|
Relative: |
<some absolute time> + <delay> where |
|
Delay is: |
<some number> [minuteshoursdaysweeks] |
|
Verbal: |
noon, midnight, teatime, AM, PM, tomorrow, + |
Example: To run the script "backup.sh" at midnight, use
at midnight -f backup.sh
Example: To find out what job number the job submitted in the previous example is, type
atq
which would produce results like this one
3 1999-07-25 00:00 a
Example: To cancel execution of the script "backup.sh" as implemented in the previous examples, type
atrm 3
|
-V |
Display version information. |
|
-q queue |
Specify a queue. Valid values for queue are [a-z][A-Z], and = for currently running jobs. Default values are a for at and b for batch. Queues with higher
|
|
-m |
Send mail to the user when the job finishes running. |
|
-f file |
Commands to be run will be taken from the specified file, rather than the standard input. |
|
-l |
List queued jobs. |
|
-d |
Remove previously queued job. |
|
-v |
For atq, this command shows completed, but not yet deleted, jobs in the queue. For all others, it shows the time the job will be executed. |
|
-c |
Display the jobs listed on the command line to standard output. |
crontab
[ -u user ] file
crontab
[ -u user ] { -l -r -e }
Crontab is the command used to maintain your list of cron jobs. A cron job is a job scheduled to be executed automatically by the system at some specified time or interval. In order for this to work, the cron daemon must be running.
Confusingly, cron jobs are stored in files that are also called
crontabs.
On most systems, each user can set up his or her own
crontab.
(It is possible to configure cron such than no one but the superuser can use cron.) If your user
When you use crontab for the first time, your default editor (usually vi) is invoked and you're looking at a blank file. You use crontab by adding and deleting entries from this file. Entries are in the following format:
|
Variable: |
minutes |
hours |
day-of-month |
month |
weekday |
command |
|
Range: |
0-59 |
0-23 |
1-31 |
1-12 |
0-6 |
[any command] |
When you're done editing, quit out of the editor the normal way. Cron will look at what you've done and tell you if you made any formatting errors. Otherwise, the jobs will be executed as specified. Note that for the weekdays field, 0 = sunday.
|
|
Depending on what you're trying to do with cron, some of the fields will always be blank.
Always mark the unused fields with
|
Example: To edit your crontab, use
crontab -e
To run the shell script "cleanup.sh" at midnight on Fridays, add the following line to the crontab file:
0 0 * * 5 crontab.sh
|
|
You can, technically, edit your cron files without using crontab. But it isn't a good idea. |
|
-u user |
Specify a crontab other than the default. |
|
-l |
List the crontab to standard output. |
|
-r |
Remove the entire crontab. |
|
-e |
Edit the crontab. Note that when you exit the editor, any changes you make will be automatically submitted to the cron daemon. |
sleep
[NUMBER[smhd]]…
This command is used to pause your system or to put it to "sleep" for a specified length of time. Time is specified in one of the following units:
|
s |
seconds |
|
m |
minutes |
|
h |
hours |
|
d |
days |
Example: To run the command wall < message (which displays the contents of the file "message" to the screens of all users currently logged in) after a two-minute delay, use
sleep 120; wall < message
|
--help |
Display help information. |
|
--version |
Display version information. |
usleep
[number]
This command is used to pause your system (or to put it to "sleep") for some number of microseconds.
Example: To run the command synctest twice with a delay of fifteen microseconds between executions, use
synctest; usleep 15; synctest
|
--help |
Print help information. |
|
-v |
Print version information. |