In addition to the immediate command tasks in Linux, you can also set up periodic scheduled tasks, the CentOS system has installed the At,vixie-cron software package by default, through the ATD and Crond two system services to achieve one or periodic scheduled task functions, and through at, respectively, crontab command to schedule task settings.
At one-time task settings
The at task runs only once at a specified time, and the task executes only if the ATD must be run and the time scheduled for the task must be after the current time or it will not run correctly
The AT command specifies, in turn, the time that the task is scheduled to execute, with the date as the parameter. (if only the specified time indicates that time of day, if only the specified date represents the current time of the date), then the carriage return will enter the task editing interface with only the "at>" prompt, each line is set to execute a command, you can set multiple statements at once, and then press Ctrl+d to submit the task. The commands that you set are executed sequentially at a fixed time.
1. Set task: At [Task time]
Example:
[[email protected] ~]$ at 15:40 2015-5-14
At> mkdir/home/dyq/33ddab\
At> mkdir/home/dyq/123244d<eot>//Add Task Ctrl+d submit task after completion
Job 3 at 2015-05-14 15:40
Verify after Point
[[email protected] ~]$ ls
123244D 33ddabmkdir
2. Query for tasks that have not been performed (the task is gone): ATQ
[email protected] ~]$ ATQ
12015-05-12 14:28 a Dyq
22015-05-14 15:30 a Dyq
3. Delete Task: ATRM
ATRM 2//ATRM back with the mission number.
Recurring Task settings: crontab ( Prerequisites: System service Crond must already be running )
1.crontab Configuration files and directories
Crond set up Scheduled tasks through multiple directories and files, different types of tasks are set by different configuration files
1)./etc/crontab System task profile, which saves the tasks required to maintain Linux, is generally not recommended for manual changes.
2)./var/spool/cron User Cron task configuration file storage Directory
Cron Scheduled tasks that are set by the user (using crontab) will be saved to the directory/var/spool/cron with the same file name as the user name.
The Crond daemon automatically checks for changes in/etc/crontab files,/etc/cron.d/directories, and/var/spool/cron/directories, and automatically loads the memory if changes occur without restarting the Crond daemon.
2. Manage user Scheduled tasks: crontab
Format:
Parameter:-E: Edit Scheduled Task List
-U: Specifies which user the managed scheduled task belongs to and, by default, for the current user, typically only the root user has permission to use this option (for editing, to delete other users ' scheduled tasks)
-L: List shows scheduled tasks
-R: Delete Scheduled Task List
1). Edit the user's scheduled task list: CRONTAB-E
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
Each line of the task configuration contains six data fields, each representing a different meaning
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
Each field is different in its value range, and the command action set in the crontab task configuration record is executed at all times.
Value Range Description
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
* Indicates any time in the range of values
In addition to *, you can also use the minus sign "-" comma "," slash "/" a complex time expression with numbers "
Minus "-": can represent a continuous range of time, such as "1-4"
Comma ",": can represent a discontinuous range of intervals, such as "3,4,5"
Slash "/": Can be used to specify the frequency of the interval, as in the Date field */3 represents each three days
Instance:
1). User Root Schedule the following tasks
#crontab-E//Start editing tasks
7 * * */sbin/service sshd start//7:50 start sshd service per day
1 1 */5 * */bin/rm-rf/var/ftp/pub/*//Every five days delete all files under/var/ftp/pub/
7 * * 6/sbin/service httpd restart//7:30 restart httpd service per Saturday
* * * 1,3,5/bin/tar JCF httpdconf.tar.bz2/etc/httpd//weekly 1,3,5 use tar to back up the contents of/etc/httpd once.
2). CRONTAB-E- u dyq//Let the general user Dyq perform the following scheduled tasks, that is, to make this program task to DYQ execution
* * 7/bin/cp/etc/passwd/home/jerry/pwd.txt//Sunday 23:55 each week, the contents of/etc/passwd CP into the./pwd.txt file.
Attention:
1. The target of the scheduled task (own, or other user) there is no execute permission on this command, the permissions should be noted here.
2. The command to schedule a task is best to write the absolute path to the command to avoid missing the execution path and not be able to execute it. For example (/BIN/CP)
3. When you plan to perform tasks on a daily basis, specify the time in hours and minutes, or you will be executed every minute. Don't mean 0:0, it's easy to make mistakes.
View the user's Scheduled Tasks list
Command: crontab-l//Can see which tasks the user has planned for themselves
Ls-l/var/spool/cron/dyq//Again, the name of the scheduled task file is the same as the user's own name.
To delete a user's scheduled Tasks list
Crontab-r//Delete Scheduled Tasks, the command by default is to delete the user's own scheduled tasks, if you need to delete other people's scheduled tasks, directly under the/var/spool/cron directory directly modify it.
Crontab-r//Delete all scheduled Tasks
If you want to delete a task, direct vim inside to modify the content.
Because a scheduled task can only accomplish a single command task, if you encounter a complex task, you typically write the command as a shell script, and then create a scheduled task that invokes the shell script to perform the scheduled task.
This article is from the "start from 0" blog, please be sure to keep this source http://0kaishi.blog.51cto.com/9457500/1679069
Scheduled Task management