Linux timed task cron configuration instructions

Source: Internet
Author: User

Linux timed tasks are: cron, Anacron, at, and most of the cron tasks are used

noun explanation

cron--service name; a daemon that performs a periodic task or waits for some event to be processed under Crond--linux, similar to a scheduled task under Windows; crontab--is a custom scheduled task table

Package Installation

To use the Cron service, install the Vixie-cron package and the Crontabs package first, and the two packages function as follows:

The Vixie-cron package is the main program for Cron. The Crontabs package is a program used to install, uninstall, or list tables used to drive the cron daemon.

  To see if a cron package is installed: Rpm-qa|grep Vixie-cron

To see if the Crontabs package is installed: Rpm-qa|grep crontabs

If not, execute the following command to install the package (package must exist)
RPM-IVH vixie-cron-4.1-54.fc5*
RPM-IVH crontabs*

If you do not have a local installation package, you can install it online if you have a network connection

Yum Install Vixie-cron
Yum Install Crontabs

See if the Crond service is running

Pgrep Crond or/sbin/service crond status or Ps-elf|grep crond|grep-v "grep"

Crond Service Operations Command

/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

Configure Scheduled Tasks

Cron has two configuration files, one is a global profile (/etc/crontab), is for system tasks, and a set of configuration files generated by the crontab command (Files under/var/spool/cron), is for a user. Scheduled tasks can be configured to any one of them.

To view the global configuration profile configuration: Cat/etc/crontab

---------------------------------------------
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/

# Run-parts
* * * * * Root run-parts/etc/cron.hourly
4 * * * Root run-parts/etc/cron.daily
4 * * 0 root run-parts/etc/cron.weekly
4 1 * * Root run-parts/etc/cron.monthly
----------------------------------------------

To view scheduled tasks under a user: Crontab-l or cat/var/spool/cron/user name

Crontab Task Configuration Basic format

  

* * * * * command
Minutes (0-59) hours (0-23) Date (1-31) month (1-12) week (0-6, 0 for Sunday) command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run

In any of these values, an asterisk (*) can be used to represent all valid values. For example, an asterisk in a month value means that the command is executed monthly after other constraints have been met.
The short line between integers (-) specifies an integer range. For example, 1-4 means integers 1, 2, 3, 4.
Specify a list with a series of values separated by commas (,). For example, 3, 4, 6, 8 indicate these four specified integers.
A forward slash (/) can be used to specify the interval frequency. Adding/<integer> after a range means that integers can be skipped within the range. For example, 0-59/2 can be used to define every two minutes in the Minutes field. The interval frequency value can also be used with asterisks. For example, the value of */3 can be used in the month field to indicate that the task runs every three months.
The line that starts with the pound sign (#) is a comment and will not be processed

Working with instances

Example 1: command is executed every 1 minutes

Command: * * * * * command

  

Example 2:3rd and 15 minutes per hour of execution

Command: 3,15 * * * * command

Example 3: Execution at 3rd and 15 minutes from 8 o'clock in the morning to 11.

Command: 3,15 8-11 * * * command

Example 4:3rd and 15 minutes of every two-day 8 o'clock in the morning to 11-point execution

Command: 3,15 8-11 */2 * * command

Example 5:3rd and 15 minutes of each Monday from 8 o'clock in the morning to 11.

Command: 3,15 8-11 * * 1 command

Example 6:21:30 restart of SMB per night

Command: * * * */ETC/INIT.D/SMB restart

Example 7:4:45 restart SMB per month for 1, 10, 22nd

Command: 4 1,10,22 * */ETC/INIT.D/SMB restart

Example 8:1:10 restart SMB per Saturday, Sunday

Command: 1 * * 6,0/ETC/INIT.D/SMB restart

Example 9: Restart SMB every 30 minutes from 18:00 to 23:00 daily

Command: 0,30 18-23 * * */ETC/INIT.D/SMB restart

Example 10: Every Saturday night at 11:00am restart SMB

Command: 0 * * 6/ETC/INIT.D/SMB restart

Example 11: Restart SMB every hour

Command: * */1 * * * */ETC/INIT.D/SMB restart

Example 12: Restart SMB every hour from 11 o'clock to 7 in the morning

Command: * 23-7/1 * * * */ETC/INIT.D/SMB restart

Example 13:4th per month with 11 points per Monday to Wednesday restart SMB

Command: 0 4 * MON-WED/ETC/INIT.D/SMB restart

Example 14:4-point restart of SMB on January 1

Command: 0 4 1 Jan */ETC/INIT.D/SMB restart

Example 15: Execution of scripts within/etc/cron.hourly directory per hour

Command: * * * * *root run-parts/etc/cron.hourly

Description

Run-parts This parameter, if you remove this parameter, you can write a script name to run, not the directory name.

Linux timed task cron configuration instructions

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.