Label:
Task Scheduler Linux Scheduled Tasks Linux Task Scheduler Crontab
There are three types of Linux scheduled tasks:
at: Specify a time to perform a task (one or more tasks, once executed, not used)
Cron: Perform tasks automatically based on a schedule (with one or more tasks, periodically)
System-level scheduled tasks and their extensions Anacron: Automatically perform tasks after a specified interval is missed
I. At service: Schedule a task to execute in the future, requiring a ATD system background process
#at now+2 minutes Enter
> enter the command to execute
>ctrl+d End Input
ATQ; Querying the current wait task
Use ATQ to query, the task has been running, it disappears. This is the focus of the at task, run only once
ATRM: Delete Wait task
After you start a scheduled task, you can use the ATRM command to delete the scheduled task if you do not want to start it.
Format: ATRM task number
The command is followed by the scheduled task number, which, if not followed, removes all scheduled tasks for the user.
You can also go to the/var/spool/at directory to delete the scheduled tasks, the scheduled tasks of the files are stored in the directory, you can use the Rm-f file name to delete (as a file to delete the scheduled task, because the scheduled task is saved in the directory as a file)
Under normal circumstances, this command can be used by super users. For other users, the ability to use it depends on two files:/etc/at.allow and/etc/at.deny
If you want to make a user unable to use the scheduled task, just write his user name in it, a row can only write one.
Allow and deny are written at the same time.
Second, cron service
Some of the cron processes and controls are briefly described above. Let's look at how Cron is implemented.
The advantage of relative vs. At,cron is the ability to execute a command periodically, at but only once
Cron background process name is Crond, Cron is also system V services, so we can service crondstart|stop to start and shut down the service, you can also use Chkconfig or NTSYSV to choose the default cron service to open, These are the orders we've all talked about before.
#crontab-e Edit the current user's cron table
#crontab-L View the current user's cron table
#crontab-R Delete the current user's cron process
#crontab-u username controls the cron table as a user
There is also an important point of knowledge, that is, when the user's scheduled task is established, it is stored in the/var/spool/cron directory
When you edit the cron table for the current user using CRONTAB-E, a VI file appears, and the cron format is like this. Divided into two columns, the left is the time, the right is the command to run. Time is made up of 5 parts.
Cases:
* * * * * * Wall Hello Everyone
5 asterisks represent: Minute hour day-of-month month-of-year day-of-week time-sharing week, and wall Hello everyone this is the command content. The above consciousness is the weekly broadcast helloeveryone per hour per day of every month. You can define your own time. If you want to send every two minutes, use */2 instead of the first *. It can also be expressed in a specific time.
Crontab–e editing tasks do not join the user name
The first * asterisk represents the first minute of the hour: the minute range is from 0-59
The second * asterisk represents the number of hours per day: Hour range is from 0-23
The third asterisk represents the day ordinal of a month: Day-of-month range from 1-31
The fourth * Asterisk represents the first month of the year: Month-of-year range from 1-12
The fifth * Asterisk represents the weekly days of the week: Day-of-week range from 0-6, of which 0 represents Sunday
User name: That is, the execution of the program to be executed by which user, this generally can be omitted;
Command: Commands and arguments to execute.
What if I want to show September 10 25 minutes to execute LS var/spool/cron task?
9 * ls Var/spool/cron
*/1 * * * 0 Wall Hello redking.blog.51cto.com
* * Indicates every number of minutes to execute ha ~
When a cron task is established, it can be viewed in crontab-l or in the/var/spool/cron/directory. The file name inside is the cron task for the user.
You can use Crontab-r to delete the current user's Cron
What is the difference between a timed run of Vim/etc/crontab and Crontab-e writes?
Vim/etc/crontab: The owner and group of Crontab,/etc/crontab that are defined at the system level are root
CRONTAB-E: is a user-defined crontab that all users can write to
The two methods record different locations, one in/etc/and the other in/var/. are called by the cron service ha ~
Third, system-level planning tasks and their expansion anacrontab
Anacrontab is the extended file for system Scheduled tasks: Automatically perform tasks after a specified interval is missed
This is the system set up, clean up the system garbage or automatic execution of certain scripts of the system tasks, generally we do understand, do not change
Configuration file is/etc/anaconrtab
1. #/etc/anacrontab:configuration File Foranacron
2. # See Anacron (8) and Anacrontab (5) for details.
3. shell=/bin/sh
4. Path=/sbin:/bin:/usr/sbin:/usr/bin
5. Mailto=root
6. # # # # #格式是这样的: Period (frequency. Days) delay (delay, minutes) Job-identifiercommand
7.1 cron.daily run-parts/etc/cron.daily
8.7 Cron.weekly run-parts/etc/cron.weekly
9. cron.monthly run-parts/etc/cron.monthly
SHELL: The interpreter that runs the scheduled task, the default is bash
PATH: Environment variable that executes the command
MAILTO: The departing user of a scheduled task
Home: Home directory for/
Run-parts is a script that, in/usr/bin/run-parts, functions to execute all scripts/programs in a directory.
Run-parts/etc/cron.hourly executes all scripts/programs under directory/etc/cron.hourly/.
Run-parts below is the command to run
The first line means: 65 minutes a day after the boot to check whether the cron.daily file is executed, if not executed today to execute his
The second line means: Every 7 days after the boot 70 minutes to check whether the cron.weekly file is executed, if not executed within a week to execute his
And at the same time, is/etc/cron.deny this configuration file to control, while writing allow and deny, allowed. That's the Linux mission.
Configure Linux Task Scheduler