Periodic tasks in Linux-general Linux technology-Linux technology and application information. For more information, see the following section. Periodic task cron in Linux (Task trigger crontab)
1. scheduled tasks
Crond is a linux Command Used to regularly execute programs.
After the operating system is installed, the task scheduling command is started by default.
The crond command periodically checks whether there is any job to be executed every minute. If there is any job to be executed, the job is automatically executed.
Linux task scheduling mainly includes the following two types:
A. work performed by the system: work to be performed periodically by the system, such as backing up system data and clearing Cache
B. Personal Work: The work that a user does on a regular basis, such as checking whether there are new emails on the email server every 10 minutes. This work can be set by each user.
Crontab is a scheduled task trigger in UNIX systems. Its user permissions are recorded in the following two files:
File description
/Etc/cron. deny the users listed in this file cannot use the Crontab command
/Etc/cron. allow users listed in this file can use the Crontab command
/Var/spool/cron/is the crontab file of all users.
/Var/spool/cron/crontabs
2. Command crontab
The Crontab command is in the following format:
Crontab [-u username]-l |-r |-e. Its Parameter meaning:
Crontabl-l display the contents of the user's Crontab file (list)
Crontabl-r: delete a user's Crontab file from the Crontab directory
Crontabl-e edit the user's Crontab file (edit)
The Crontab file created by the user is saved in/var/spool/cron, and its file name is consistent with the user name.
The format is divided into six segments. The first five segments are time segments, and the sixth segment is the command segment to be executed. The format is as follows:
Minute hour day month dayofweek command
*****
The meaning of the time period:
Value Range
-------------------------
Section 1st represents minute 0-59 in minutes
Section 2nd represents hour 0-23
Section 3rd represents the date day 1-31
Section 4th represents month 1-12
Section 5th dayofweek 0-6 of the day of the week, and 0 represents Sunday
3. Meaning of the example
0 */2 ***/sbin/service httpd restart apache every two hours
50 7 ***/sbin/service sshd start enable the ssh service at every day
50 22 ***/sbin/service sshd stop Close ssh service at every day
0 0 ** fsck/home check/home disk on the 1st and 15th of each month
1 ***/home/bruce/backup execute the file/home/bruce/backup every 1st minutes of the hour
30 6 */10 ** ls: Execute the ls command at on the 1st, 11, 21, and 31st of each month.
00 03 ** 1-5 find/home "*. xxx"-mtime + 4-exec rm {}\;
From three o'clock every Monday to Friday, find the file named *. xxx in the directory/home and delete the file four days ago.
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