Scheduled Task 一、一次 Task
at command #功能: Schedule One / several commands at a specified time ( moment ) Run Once
1, at the command format and Parameters
At [-f filename ] time
at-d or ATRM Delete a task in a queue
" at generated files are saved in the /var/spool/at directory"
At-l or ATQ view the tasks in the queue
2, at the specified time mode
Absolute timing method [ recommended ]
Legal Time: Midnight Noon Teatime
hh:mm [Today]
HH:MM tomorrow
hh:mm Week
hh:mm mm/dd/yy[ recommended ] "DD. Mm. YY YYMMDD"
Relative Timing method
Now + N minutes
Now + N Hours
Now + N Days
Example
Specifies that 17:30 execute a command this afternoon ( Assuming the time is now 14:30,2011 1 months in the afternoon Day )
At 5:30pm
At 17:30 [Today] #today can be omitted
At now + 3 hours
At now + minutes
At 17:30 11.1.11
At 17:30 1/11/11
3. at use example
I. Interactive mode
At 9:xx
Ii. How to use script files
1. Generate at.script file
2. Using at command
At-f at.script 9:00 1/11/11 or at < At.script 9:00
Attached-at scheduled task files are saved in the /var/spool/at/ directory
Attached-finger [+username]: View scheduled tasks in the system
If at has not started, manually start with:/etc/rc.d/init.d/atd start or service ATD Start
4, at the execution result and the configuration file
If/etc/at.allowFile exists,then only users who are listed in this file can use the atCommand;if/etc/at.allowfile does not exist,the Check/etc/at.denywhether the file exists. If/etc/at.denyexist,users who are listed in this file cannot use the atcommand. If none of the two files exist,only super users can use the atcommand. If all two files are present and are empty,All users can use the atcommand.
Batch command "not used"
1. function : Arrange one or more commands to run once when the system load is light ( under normal load, the average load drops to 0.8 following ).
2, using the method with at, almost identical , generally is not important when the transaction use the command
Man explanation : Batch executes commands when system load levels permit; in other words, when the load average drops Below 0.8, or the value specified[ specified] in the invocation[ prayer ] of ATD.
Ii. Periodic Scheduled Tasks
Crontab Command
1. function : the crontab file needed to generate the cron process
2. Format:crontab {-l|-r|-e}
-L Display current crontab content
-R Delete Current crontab"All clear , not recommended "
-e Use the editor to edit the current crontab file.
3.crontab file format
"minute hour day-of-month month-of-year day-of-week commands "
" minutes , hours, days, months, weeks, a few commands / scripts "
Minute which minute of the hour [0~59]
Hour hour of the day [0~23] " hour System"
Day-of-month the day of January [1~31]
Month-of-year month of the year [1~12]
Day-of-week Day of the week [0~6]
Commands executed by commands
"Minutes:*/2: Every two minutes"
"Hours:*/1: Every one hours 12-14: from a point to a point "
" Add the time value you know and fill in the time value you don't know. "
e.g
*/2 12-14 * 3-6,9-12 1-5/bin/sh/root/cron.script >/dev/null 2>/root/cron.err
4. Notes on Writing
I. The time value selection cannot be empty , must fill in
II. The value of the item that is not known / does not need to be set use the wildcard character * to indicate any time
Iii. multiple values can be specified for each time field , discontinuous values are used in the "," interval , continuous values are used "-" interval.
Iv.. the command should give the absolute path
V. The user must have permission to run the corresponding command or program
VI. the scheduled task should also keep some additional information, such as error messages, etc.
5.crontab configuration file /etc/crontab
# The last few lines of the old Linux , define the hourly, daily, and so on the specific time system's Cycle execution task
6.cron configuration file
Role: Restrict which users can use the crontab command , with the same effect as at
/etc/cron.allow
/etc/cron.deny
Once the attached-crontab file is established , it can be found in the /var/spool/cron/ directory , You can view the contents of the file :more/var/spool/cron/root, the information obtained is like crontab-l
Attached- if Crod does not start , manual start is required:/etc/rc.d/init.d/crond start
Third, process processing methods
1,standalone independent operation, continuous resident system , consumption of system resources , monitoring customer requests
2,xinetd Process Hosting, the Internet Super Daemon , by xinetd to listen to customer requests , and send it to the relevant process , rather than a service to personally monitor
3,ATD,crond Scheduled Tasks, every minute , Wake up from sleep and check for tasks that need to be performed
Attached - for security reasons , both the timed task and the subsequent Shell script must write the absolute path of the command !
Linux Process Management (second edition)--Scheduled Tasks