Linux under Crontab detailed

Source: Internet
Author: User

1. Overview:

Crond is a daemon that is used to periodically perform certain tasks or wait for certain events under Linux, similar to Scheduled tasks under Windows, when the operating system is installed, the Service tool is installed by default and the Crond process is started automatically. The Crond process periodically checks to see if there is a task to perform and automatically executes the task if there are tasks to perform.

2. Classification of Task scheduling:
    • System task scheduling: The work to be performed by the system periodically, such as writing cache data to hard disk, log cleanup, etc. In the/etc directory there is a crontab file, this is the System Task Scheduler configuration file.

The first four rows are the environment variables that are used to configure the Crond task to run

The first line of the shell variable specifies which shell the system will use, and this is bash

The second line of PATH variable specifies the path of the System execution command

The third line of the mailto variable specifies that Crond's task execution information will be emailed to the root user, and if the value of the mailto variable is null, the task execution information is not sent to the user

The four-row home variable specifies the home directory to use when executing the command or script.

The meaning of line sixth to Nineth is described in detail in the next section. There's not much to say here.

    • User Task scheduling: Users to perform regular work, such as user data backup, scheduled email reminders and so on. Users can use the Crontab tool to customize their own scheduled tasks. All user-defined crontab files are saved in the/var/spool/cron directory. Its file name is the same as the user name.

3. Crond Service
    • Install Crontab:

# yum Install Crontabs

    • Service Operation Instructions:

#/sbin/service Crond Start//Startup service

#/sbin/service Crond stop//Shut down service

#/sbin/service crond Restart//Restart service

#/sbin/service Crond Reload//Reload Configuration

    • View Crontab Service Status:

#service crond Status

    • To start the Crontab service manually:

#service Crond Start

    • To see if the Crontab service is set to boot, execute the command:

#ntsysv

Add to boot auto start:

#chkconfig –level Crond on

    • Terminating task scheduling

#crontab-R

    • List Current task schedules

#crontab –l

4. Crontab Usage Instructions

5. Set up User Task Scheduler

#crontab –e

#输入 * * * * * ls–l/etc/>/tmp/to.txt

Note: * represents every minute, hourly, daily, monthly etc.

6. Another way to set up crontab

Create the shell file first, and then set the shell file to execute in crontab

    • #vi/tmp/mytask.sh

    • Change the permission type of the mytask.sh file (readable writable executable)

#chmod 744 mytask.sh

    • #crontab –e

Append INPUT * * * * * */tmp/mytask.sh

    • Here we can see the To1.txt file created by crontab

    • View current Task Schedule

Linux under Crontab detailed

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.