Periodic tasks under Linux (Task Scheduler)-read Linux system Management technology finishing

Source: Internet
Author: User

Recurring Process (Task Scheduler)

Task Scheduler: Perform one or a series of tasks at some point in the future. Execution results are sent to the administrator in the form of a message

When Cron starts, he reads the configuration files, saves them in memory, and then goes to sleep. Every minute, Croon wakes up, checking the crontab file for modification times. Reload any changed files, and then in return to sleep, perform this one-minute scheduled task.


1, configuration file:crontab, is the abbreviation of cron table
Cron finds files in three places,/var/spool/cron,/etc/cron.d,/etc/crontab, and crontab files for each user are stored in the/var/spool/cron directory. A user corresponds to a file. The system user is placed under/ETC/CRON.D or/etc/crontab

2, the System cron task
Under/ETC/CRON,/ETC/CRON.D configuration, this is a parallel relationship that has the system administrator assigned to both directories.


3, other ordinary users of the task
A file named after the user name of the normal user is generated under/var/spool/cron.

4. Format of crontab file
Minute hour day month weekday [Username] Command
Minutes, hours, months, and weeks. Commands executed by the user


Minutes: 1-59
Hours: 1-23
Days: 1-31
Month: 1-12
Weeks: 0-6 (0 for Sunday)

Each time-related field can have (a time wildcard):
*: can represent all
-: [1-5] minutes, can represent a range
,: Comma separated to indicate multiple points of time that are not contiguous
Integer: Exact match
/#: Each time within the corresponding range, 20/2 * * 1, every two hours in Monday, every 20 minutes


Example:
1, 45 10 * * 1-5
From Monday to Friday, 10.45 a.m.
2, 0,30 * 13 * 5
Weekday and day are specified to meet one of the two conditions.
The above represents: every half-hour of Friday, or every half-hour of 13th per month
3, 2 * * 1 (cd/users/joe/project; make)
2.30 in the wee hours of Monday, run make in the/users/joe/project directory
4, 1 * * * * find/tmp-atime +3-exec rm-f {} '; '
1.20 per day, delete files in/TPM directory, 3 days without access

crontab Management

All operations of crontab are for the current user:

Crontab-l: Lists tasks for the current user
CRONTAB-E: Edits a task (as the current user's identity) or can be used to create a new task
Crontab-r: Remove All Tasks
Crontab-u Username: Managing other users

you can specify which users can submit crontab files by using the/etc/cron.allow and/etc/cron.deny configuration files.

ls/etc/cron*cron.hourly/cron.weekly/cron.daily/cron.monthly/

These four directories have the corresponding program, they will run at the corresponding time (with the suffix known), which is the system's own periodic task

Common uses of cron
1. Clean up the file system

Find/-xdev-type F ' ('-name core-o name ' core.[ 0-9]* ') '-atime +7-exec rm-f {} '; '

Delete the core image files that were not accessed in one weeks.
-xdev: Make sure the Find command does not go to the file system outside the root filesystem.
-type f:linux Kernel Source code includes a directory also called Core, it should not be deleted.

Find/-xdev-atime + 3 ' ('-name ' #* '-o-name '. #* '-o-name ' *. CKP '-o-name ' *~ '-o-name '. nfs* ') '-exec rm-f {} '; '

Remove the files that begin with #,. #或者. NFS, or to ~ and. CKP end and three days without access to the file

cd/tmp; Find. ! -name. ! -name lost+found-type d-mtime +3-exec/bin/rm-rf {} '; '

Recursively delete all subdirectories under/tmp that have not been modified within 72 hours


Other scheduling procedures: ANACRON
Anacron:cron supplement, make up the cron should the system when the machine or machine time appears discontinuous situation and did not execute to the corresponding command.











This article is from the "Small City Studio" blog, please be sure to keep this source http://xcroom.blog.51cto.com/7941996/1661744

Periodic tasks under Linux (Task Scheduler)-read Linux system Management technology finishing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.