Linux scheduled task system cron entry

Source: Internet
Author: User
Linux scheduled task system cron entry

Cron is a Linux scheduled execution tool that can run jobs without human intervention.

1. Start and close the service:
Since cron is a built-in service in Linux, but it does not automatically get up, you can use the following methods: #/sbin/service crond start // start the service #/sbin/service crond stop // close the service #/sbin/service crond restart // restart the service #/sbin/service crond reload // re-load the configuration. You can also enable the service automatically when the system starts: in/etc/rc. d/RC. add/sbin/service crond start at the end of the local script. Now the cron service is already in the process and we can use it.

 

2. directly use the crontab command to edit
The cron Service provides the crontab command to set the cron service. The following are some parameters and descriptions of this command: # crontab-u // set the cron service of a user, generally, the root user needs this parameter when executing this command # crontab-l // list the details of a user's cron service # crontab-r // Delete the cron service of no user # crontab-E // edit the cron service of a user, for example, view your cron settings as root: crontab-u root-l again, for example, Root wants to delete the cron setting of FRED: crontab-u Fred-r when editing the cron service, the edited content has some formats and conventions. input: crontab-u root-e enters the VI editing mode. The edited content must comply with the following format: */1 ***** ls>/tmp/ls.txt

 

Iii. crond resident command for Task Scheduling
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. 1. Linux task scheduling is divided into the following two types: * system execution: The work to be executed by the system periodically, such as backing up system data and clearing cache * personal execution: 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, can be set by each user. 2. crontab command option:-u specifies a user,-l lists a user's task plan,-r deletes a user's task, and-e edits a user's task. 3. cron File Syntax: hour, day, month, week, command 0-59 0-23 1-31 1-12 0-6 (value range, 0 indicates that a task is usually displayed in a row on Sunday) 4. remember the meanings of several special symbols: "*" indicates a number in the value range, "/" indicates "every", "-" indicates a number from a number to a number ,", "Separate several discrete numbers
Iv. Writing of the task scheduling setting file
You can use the crontab-e command to edit the cron file of the corresponding user in/var/spool/cron. You can also directly modify the format of the/etc/crontab file as follows: minute hour day month dayofweek command minute hour day month day weekly command each field represents the meaning of the following: minute executes this task in the minute of each hour. Hour executes this task in the hour of every day. day of every month. Run this task in the month. day of every year. Run this task in the day of every week. execute this task command to specify the program to be executed in these fields, except that "command" is a field that must be specified each time, other fields are optional fields, which can be determined as needed. For unspecified fields, use "*" to fill their positions. Example: * ls indicates that the LS command is executed once every 5th minutes of every hour. * 5 * ls indicates that the LS command is executed at every day. * 7 8 * ls indicates the 8 th day of every month. execute the LS command at AM 30 5 8 6 * ls to specify to execute the LS command at AM on April 9, June 8*0 ls to specify to execute the LS command at AM on every Sunday. [Note: 0 indicates Sunday, 1 indicates Monday, and so on. Sun indicates Sunday, mon indicates Monday, and so on.] 30, 20 ** ls: Execute the LS command at on the 10th and 20th of every month [Note: ", [Note: "-" is used to connect to consecutive periods] */15 ***** ls executes the LS command every 15 minutes [that is, the LS command is executed every hour for 0th 15 30 45 60 minutes] 30 6 */10 ** ls every month, run the LS command at every 10 days [that is, run the LS command at on the 1st, 11th, 21st, and 31st of every month] Run the command at every day as root/etc/cron. all executable files in the daily directory are 50 7 * root run-parts/etc/cron. daily [Note: Run-parts parameter indicates that all executable files in the following directory are executed.]
5. New scheduling tasks
There are two ways to add a scheduling task: 1. # crontab-E. Then, add the corresponding task and exit the WQ disk. 2. directly edit the/etc/crontab file, that is, VI/etc/crontab, and add the corresponding task.
6. View scheduling tasks
# Crontab-l // list all current scheduling tasks # crontab-l-u JP // list all scheduling tasks of user JP
VII. Delete Task Scheduling
# Crontab-r // delete all task scheduling tasks
VIII. redirection of task scheduling execution results
Example 1: Execute the LS command at every day and output the result to the/jp/test file for 30 5 * ls>/jp/Test 2> & 1 Note: 2> & 1 indicates the execution result and error message.
Edit the/etc/crontab file and configure the cron service to read not only all files in/var/spool/cron once per minute, but also/etc/crontab once, therefore, we can use the cron service to configure this file. Crontab configuration is intended for a user, and editing/etc/crontab is a system task. The file format of this file is: shell =/bin/bash Path =/sbin:/bin:/usr/sbin:/usr/bin mailto = root // if an error occurs, or there is data output. The data is sent to the account home as an email = // path for the user to run, here is the root directory # Run-parts 01 ***** root run-parts/etc/cron. hourly // run/etc/cron hourly. hourly script 02 4 *** root run-parts/etc/cron. daily // run/etc/cron every day. daily script 22 4 ** 0 root run-parts/etc/cron. weekly // run/etc/cron every week. weekly script 42 4 1 ** root run-parts/etc/cron. monthly // Execute/etc/cron every month. note the "run-parts" parameter for the script in monthly. If this parameter is removed, you can write a script name to be run later, instead of the folder name. For example: 1. Enter crontab-E in the command line and add the corresponding task. The WQ disk will exit. 2. directly edit the/etc/crontab file, that is, VI/etc/crontab, and add the corresponding task, such as 11 2 21 10 * Rm-RF/mnt/FB.
Related Article

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.