In this chapter, we mainly describe two command at (batch) and crontab, where batch can be understood as a special way of execution of at.
at: is a command that can handle the end of the dispatch only once, need ATD service;
crontab: The work that it sets up will be carried out continuously, need crond service;
Work schedule only once: at
1. Open the ATD Service
# /ETC/INIT.D/ATD Restart//Restart ATD Service
# Chkconfig ATD on//Join boot up
2. How the at operates
execution Logic: In fact, we use the AT command to generate the work to be run, and to write the work as a text file into the /var/spool/at/ directory, which waits for the ATD of the service to be taken and executed.
permission control: Not everyone can do at work scheduling;
1) First look for the /etc/at.allow file, only the user exists in this file can use at, does not exist not allowed to use, even if it does not exist in the/etc/at.deny;
2)/etc/at.allow does not exist, look for/etc/at.deny, exists in the file is not allowed to use at, does not exist is allowed to use
3) If none exists, only root can use the at
Note: There is an empty/etc/at.deny on the general system, meaning that all users can use at;
3. At operation
3.1 Command format
# at [-MLDV] Time
# at-c Work number
Here is not given at the parameter interpretation, all kinds of use, just give examples to reference, otherwise it is not a summary, but plagiarism, but also want to go to bed early! ^_^
EG 1:
# at now + 5 minutes
At>/bin/sync//Enter at Shell environment
At>/bin/sync//Use absolute path, because at run time, run to the working directory when the AT command is executed
At>/sbin/shutdown-h now
at><eot>//Input CTRL + D as the Terminator, remember to write the message terminator? O, daming Lakeside
EG 2:
# at now + 3 minutes
at> echo "Hello"//Hello is not displayed to the terminal because the execution of the at is not related to the terminal environment, Stdout/stderrout is sent to the performer's mail
At>echo "Hello tty" >/dev/tty1//force output to tty1 terminal, so it's OK.
At><eot>
Offline characteristics of 3.2 at
At has the ability to perform in the background, that is, when a task is defined with an at, the end environment can be switched off, because the work defined in at is managed directly to the ATD service, regardless of the current bash environment.
Management of 3.3 at work
ATQ = at-l//Query
ATRM = at-d//delete
Introduction of 3.4 Batch
Background: When the system is very busy executing at, this is not very reasonable, then how to do?
Batch: Perform background tasks when the system is idle.
The criteria for batch judgment idle are: CPU load AVG < 0.8; load Avg:cpu The number of jobs that are responsible at a single point in time, not CPU usage.
For example: There is a program that has been using CPU computing power, the CPU usage may be 100%, and load avg is just close to 1
Eg:
# Batch now + 5 minutes
At>/sbin/sync
At>/sbin/sync
At> Shutdown-h Now
At><eot>
Also use ATQ, ATRM to manage the tasks defined by batch; So I'll start by saying that batch is a special form of at.
Just write it, see it for a while, but it's not so easy to write ... Insist
"Bird's Linux Private Cuisine" chapter 16th routine work (crontab)