Centos command -- crontab

Source: Internet
Author: User

The crontab command is used in linux systems to set periodically executed commands. The crontab file contains a series of jobs and commands sent to the cron daemon. Each user can have their own crontab file. At the same time, the operating system saves a crontab file for the entire system, which is usually stored in subdirectories under/etc or/etc, this file can only be modified by the system administrator.

Each row of the crontab file complies with a specific format and is separated by spaces or tabs into several fields. Each field can contain one or more values.

Parameters:

1. crontab-l list the current crontab task

2. crontab-d: Delete the current crontab task.

3. crontab-e: edit a crontab task

4. Use filename as the task list file of crontab and load it

Crontab format:

Rows in the crontab file are composed of six fields. Different fields are separated by spaces or the tab key. The six fields are:

Minute (0-59) hour (0-23) Date (1-31) month (1-12) day of the week (0-6, where 0 represents Sunday) command

MIN HOUR DAY MONTH DAYOFWEEKCOMMAND

Example 1: #06:10 every day

10 6 **** date

Example 2: # every two hours

0 */2 * date

Example 3: # every two hours from PM to am, am

0 23-7/2, 8 **** date

Example 4: # am on the 4th day of each month and from Monday to Wednesday of each week

0 11 4*1-3 date

Example 5: #, January 1, January 1

0 4 11 * date

  Note: When Using crontab, the environment variables that can be accessed in the running script may not be consistent with those in the current test environment, it is safer to set the environment variable (export) in the running script program)

Run as a file:

(1ndcreate a file named crond.txt as follows and restart it at 05:36 every morning.

36 5 * reboot

(2) upload to the/opt directory

(3) run the command

Crontab/opt/crond.txt

Crontab-l

  Make the configuration file take effect: If the configuration file takes effect, you have to restart crond. Remember that since the crond configuration file under each user is modified. Restart the crond server.

Scheduled task start: [start stop status restart]

[Root @ localhost ~] #/Etc/init. d/crond start // method 1

[Root @ localhost ~] # Service crond start // method 2

If you want crond to run at startup, you should change its running level;

[Root @ localhost ~] # Chkconfig -- levels 35 crond on

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.