1. Summarize the detailed usage method of the task plan (at, crontab) on Linux system;
directive: at
Timed tasks, specifying a time to perform a task that can only be performed once.
Syntax: # at [parameter] [TIME]
at> Execution of instructions
Exit at Command Ctrl+d
Command Prerequisites:
The ATD process needs to be turned on (ATD is started by default with system boot in Redhat)
[[email protected] ~]# ps-ef|grep ATD #查看是否开启atdroot 1360 1 0 September 02? 00:00:00/usr/sbin/atd-froot 17626 17581 0 10:02 pts/0 00:00:00 grep--color=auto atd[[email protected] ~]#
The query deletes the current wait task for the current pending task query, and does not display # atq Delete the work number of the task # atrm task that is being established by at in on the system, such as:# atrm 17 Common parameters:-m : When the specified task is completed, the user will be sent a message, even if there is no standard output-I&NBSP;:ATQ alias-D&NBSP;:ATRM alias-v : Shows when the task will be executed-c : Print the contents of the task to the standard output-v : Display version information-q : Add < Queue > Use the specified queue-f : Add < files later > Reads from the specified file into the task instead of reading it from the standard input-t : Back < time parameters > submit the task time to run as a time parameter: defines when to perform the at task, in the format: 1, hh:mm Description: In today's &NBSP;HH: mm time, if the time has passed, then tomorrow's HH:MM to do this task. ex> 04:002, HH:MM&NBSP;YYYY-MM-DD Description: Provisions in a certain period of a certain day of the month of the special time to carry out the task ex> 04:00 2009-03-173, hh:mm[am| Pm] [month] [date] Description: The provision of a certain period of a certain day at a certain time of the task ex> 04pm march 174, hh:mm[am|pm] + number [minutes|hours|days|weeks] Description: Specifies how much time will be added to the task at a certain point in time ex> now + 5 Minutesex> 04pm + 3 days Note 1, if the command output at the wrong path will send the results in the form of mail to the user 2, when a task is created will be assigned to a task number, and will queue up in the/var/spool/at. It is not recommended to use VI Editor to modify, error-prone. Example: Example 1: Three days in the afternoon 5 at Chung /bin/ls# at 5pm + 3 daysat> /bin/lsat> <eot>job 7 at 2013-01-08 17:00 Example 2: Tomorrow 17 o'clock , the output time is within the specified file # at 17:20 tomorrowat> date > /root/doiido.logat> < EOT>JOB&NBSP;8&NBSP;AT&NBSP;2013-01-06&NBSP;17:20 Instance 3: After you have scheduled a task, use the ATQ command to see that the system is not performing a work task before it is executed # atq8 2013-01-06 17:20 a root7 2013-01-08 17:00 a root Example 4: Delete a task that has already been set # atq8 2013-01-06 17:20 a root7 2013-01-08 17:00 a root# atrm 7# atq8 2013-01-06 17:20 a root Instance 5: Displays the task content that has been set # at -c 8#!/bin/sh# atrun uid=0 gid=0# mail root 0echo "Hello" date > The doiido.log extension directive, Batchbatch, is a special version of the AT command that is used when the task being performed consumes a lot of resources and is used only when the CPU needs less than 80% of the CPU capacity # batchat> echo The tasks created by "HI" > /dev/tty2batch are also viewed through ATQ, atrm delete
Linux crontab timed Execution of Task command format with detailed examples.
Basic format:
# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# | | .----------Day of Month (1-31)
# | | | .-------month (1-12) OR jan,feb,mar,apr ...
# | | | | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
* * * * * command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
The 6th column represents the command to run
Some examples of crontab files:
* * * * */etc/init.d/httpd restart
The above example shows that 21:30 restarts Apache per night
4 1,10,22 * */ETC/INIT.D/HTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month
1 * * 6,0/ETC/INIT.D/HTTPD restart
The above example shows that 1:10 restarts Apache per Saturday, Sunday
0,30 18-23 * * */etc/init.d/httpd restart
The above example shows that the Apache is restarted every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/ETC/INIT.D/HTTPD restart
The above example shows that 23:00 restarts Apache per Saturday
* */1 * * * */etc/init.d/httpd restart
Restart Apache every hour
* 23-7/1 * * * */etc/init.d/httpd restart
From 11 o'clock to 7 in the morning, restart Apache every hour.
0 4 * mon-wed/etc/init.d/httpd restart
4th per month with 11-point restart from Monday to Wednesday Apache
0 4 1 Jan */etc/init.d/httpd restart
4-point restart of Apache on January 1
Crontab How to use:
Parameters:
CRONTAB-E: Do a text editor to set the odometer, the default text editor is VI, if you want to use a different text editor, you first set the VISUAL environment variable to specify the use of the text editor (for example, SETNV visual Joe)
Crontab-r: Delete the current schedule table
Crontab-l: List the current schedule
crontab file [-u user]-replaces the current crontab with the specified files.
The format of the schedule table is as follows:
F1 F2 F3 f4 f5 program
Where F1 is expressed in minutes, F2 represents hours, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. Program represents the procedure to be executed.
A program is executed every hour when F1 is *, which means every minute the program,f2 is executed, and so on
When the F1 is a-B, it is executed from the minute of the first to the minute, and the F2 is a-B, which means to execute from the first to the first, and so on.
When F1 is */n, it is executed once every n minutes, F2 to */n for every n-hour interval, and so on
When F1 for A,b,c,... Indicates the A,b,c,... Minutes to execute, F2 for A,b,c,... Indicates the A,b,c,... Hours to execute, and so on
The user can also store all the settings in the file file, using the crontab file to set the time schedule.
Example:
/bin/ls is performed at 7 O ' Day in the morning:
0 7 * * */BIN/LS
In December, the/usr/bin/backup is performed every 3 hours in the morning from 6 to 12.
0 6-12/3 */usr/bin/bakup
2, every Monday to Saturday 3:20 A.M., run the CP command to archive the/etc/directory, storage location is/BACKUPS/ETC-YYYY-MM-DD;
3 * * 1-6/usr/bin/cp-r/etc//backups/etc-' date +%F '
3, every Sunday 2:30 A.M., run the CP command to backup the/etc/fstab file, the storage location is/BACKUP/FSTAB-YYYY-MM-DD-HH-MM-SS;
2 * * 0/usr/bin/cp-r/etc/fstab/backup/fstab-' date +%f-%h-%m-%s '
4, every night 12 o'clock, get all the lines in the/proc/meminfo file starting with S or M, appended to the/statistics/meminfo.txt file, and the daily message before, to add a similar =============== separator line;
0 0 * * */bin/echo "===============" >>/statistics/meminfo.txt; /bin/cat/proc/meminfo | Egrep "^s|^m" >>/statistics/meminfo.txt
This article is from the "Ah du" blog, please be sure to keep this source http://253737.blog.51cto.com/243737/1692854
September 5, 2015 Course assignments (at, crontab)