Chapter16: Routine Work (crontab): Routine work scheduling for cyclic execution

Source: Internet
Author: User
Tags crontab syntax

The routine work schedule that is executed by the loop is controlled by the cron (Crond) system service, which is initiated by default. Linux also provides user-controlled command crontab for routine work scheduling.

One. User settings

For security reasons, we can limit the users who can use crontab. Similar to at, with two files to set,/etc/cron.allow,/etc/cron.deny.

When the user uses the crontab command to create a new job schedule, the work is recorded in/var/spool/cron. and is based on the account number as a discriminant. As Chuiyuan after using this from, the work will be recorded to/var/spool/cron/chuiyuan. Do not use Vim to edit this file, because errors can occur.

crontab syntax

crontab [-u username] [-l |-E |-r]

-U: Only root can be used, that is, to help other users establish crontab work scheduling.

-e: Edit Crontab's work.

-L: View

-R: Delete all, if you want to delete only one item, then use-e to edit.

Two. System configuration File/etc/crontab

The above crontab-e is the user's cron to design, the inside of the crontab is actually/usr/bin/crontab this executable file, if it is the routine work of the system, then edit/etc/crontab This file, this is a text file.

Basically, cron This service is measured in minutes, so cron reads the contents of/etc/crontab and/var/spool/cron every minute. So when we finish modifying the/etc/crontab file, cron will automatically execute it.

It is important to note that some systems can be crontab read into memory, so after the modification, please restart the next crond this service. First Look at the contents of the/etc/crontab file.

We can modify this file ourselves, because CentOS has run-parts (a bash scripts, run all executables in the following directory) this command. So/etc/crontab this file supports two ways of executing,

One is direct command execution, and one is a directory to plan.

Three. Work tasks that can wake up downtime

If the host is not shut down for 24 hours, then we have at and Crond two services to manage our routine work schedule can be, if not 24 hours without shutdown, there will be Anacron program (not service). It is not intended to replace crontab, but to perform the anacron operation in days or immediately after the boot. It will check for crontab tasks that were not performed during the outage and perform the task once, and then the Anacron stops automatically. So anacron in fact is also through the crontab to run, so its running time is usually two, one is the system boot, one is written to the crontab scheduling.

Anacron This program in CentOS has entered the crontab schedule, view the following

Let's take a look at what's inside/etc/anacrontab.

Chapter16: Routine Work (crontab): Routine work scheduling for cyclic execution

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.