Detailed and sample crontab in Linux (collection)

cron is timing the implementation of a tool under linux, without human intervention in the case of running jobs. Cron is built as a Linux service, but it does not automatically up, you can use the following methods to start, shut down the service:

/ Sbin / service crond start / / start service
/ Sbin / service crond stop / / close service
/ Sbin / service crond restart / / restart services
/ Sbin / service crond reload / / reload the configuration

You can also start the service automatically when the system starts:
In the / etc / rc.d / rc.local added at the end of this script:
/ Sbin / service crond start

Cron is now inside the service has been in the process, we can use the service of, Cron service provides the following interfaces for your use:

1, directly edit the crontab command

cron service providers to set the cron crontab command service, the following are some of the parameters of this command and description:

crontab-u / / set a user's cron service, usually root user running this command, this parameter needs
crontab-l / / a user cron service listed the details of
crontab-r / / remove a user's cron service
crontab-e / / edit a user's cron service

For example, set the root to see your cron: crontab-u root-l
For another example, root to delete the cron setting fred: crontab-u fred-r
When editing the cron service, edit the contents of some of the formats and conventions, enter: crontab-u root-e
Enter vi edit mode, edit the content must meet the following format: * / 1 * * * * ls>> / tmp / ls.txt

The first part of this format is the time set, the back part of the command to execute if the command to execute too many, you can write these commands inside a script, then here you can directly call the script, and call when I remember to write the full path to the command. Time setting we have some agreement, on behalf of the previous five * number five figures, the range and number of meanings are as follows:

Minutes (0-59)
Hours (0-23)
Date (1-31)
Month (1-12)
Week (0-6) / / 0 for Sunday

In addition there are several numbers is a special symbol and "-",",",* "*","/" behalf of all the range of numbers, "/" represents the meaning of each "* / 5 "said the five units," - "represents a number from a number to," "separated a few discrete numbers. The following few examples illustrate the problem:

6 o'clock every morning

0 6 * * * echo "Good morning.">> / Tmp / test.txt / / Note that simply echo, not see any output from the screen, because the cron output to email to any mailbox of root.

Every two hours

0 * / 2 * * * echo "Have a break now.">> / Tmp / test.txt

11 pm to 8 am every two hours between the morning and eight

0 23-7/2, 8 * * * echo "Have a good dream:)">> / tmp / test.txt

4th of every month and every week the morning of Monday to Wednesday 11

0 11 4 * 1-3 command line

January 1, 4:00 am

0 4 1 1 * command line

Every time you edit a user's cron settings, cron automatically in / var / spool / cron to generate a file with the same name as the user, this user information recorded in the cron file, this file can not directly edit , and can only use the crontab-e to edit. cron is started every time a bell read this file to check whether to execute the command inside. This file is modified so no need to restart the cron service.

2, edit / etc / crontab cron configuration file

cron service not only to read once per minute / var / spool / cron all the files, but also read an / etc / crontab, so we can configure this file using cron service to do something. Use crontab configuration for a user, and edit / etc / crontab for system tasks. This file format is:

SHELL = / bin / bash

PATH = / sbin: / bin: / usr / sbin: / usr / bin

MAILTO = root / / If an error occurs, or a data output, data as e-mail sent to this account

HOME = / / / the user running path, here is the root directory

# Run-parts

01 * * * * root run-parts / etc / cron.hourly / / hourly / etc / cron.hourly the script
02 4 * * * root run-parts / etc / cron.daily / / perform daily / etc / cron.daily script within
22 4 * * 0 root run-parts / etc / cron.weekly / / execute each week / etc / cron.weekly the script
42 4 1 * * root run-parts / etc / cron.monthly / / month to perform the / etc / cron.monthly the script

Attention to "run-parts" of this argument, if this parameter is removed, then later you can write a script to run the name of the folder name rather than a.

--------------------------------------
Basic format:
* * * * * Command
Time-moon week command

Section 1 of minutes from 1 to 59 per minute with a * or * / 1 means that the first two hours of 1 to 23 (0 0)
Column 3 represents the date from 1 to 31
Section 4 of the month from 1 to 12
Section 5 identifies the number of weeks 0 to 6 (0 for Sunday)
Section 6 of the command to run

Some examples of the crontab file:

30 21 * * * / usr / local / etc / rc.d / lighttpd restart
The above example that night 21:30 to restart lighttpd.

45 4 1,10,22 * * / usr / local / etc / rc.d / lighttpd restart
The above example shows the monthly 1,10,22 Day 4:45 to restart lighttpd.

10 1 * * 6,0 / usr / local / etc / rc.d / lighttpd restart
The above examples show every Saturday, Sunday 1:10 to restart lighttpd.

0,30 18-23 * * * / usr / local / etc / rc.d / lighttpd restart
The above example indicates that every day 18: 00 to 23:00 every 30 minutes between restart lighttpd.

0 23 * * 6 / usr / local / etc / rc.d / lighttpd restart
The above example that every Saturday the 11: 00 pm to restart lighttpd.

* * / 1 * * * / usr / local / etc / rc.d / lighttpd restart
Lighttpd restart every hour

* 23-7/1 * * * / usr / local / etc / rc.d / lighttpd restart
11 pm to 7 am, between every hour restart lighttpd

0 11 4 * mon-wed / usr / local / etc / rc.d / lighttpd restart
Monthly on the 4th and Monday to Wednesday 11:00 to restart lighttpd

0 4 1 jan * / usr / local / etc / rc.d / lighttpd restart
January 1 to 4:00 lighttpd restart

分类:OS 时间:2011-03-10 人气:88
分享到:
blog comments powered by Disqus

相关文章

  • Cloud platform programming and development (a): List of cloud platform service providers 2011-08-23

    Cloud computing is the next IT industry trends, Next Big Thing. Many companies have launched the "cloud platform" products. Below is a list of existing service providers, by ANDYLAND summary. This "cloud platform" is a venture company

  • Insurance IT service providers are still foreign Shun Tak: bigger only "insurance" 2010-08-28

    Insurance IT service providers are still foreign Shun Tak: bigger only "insurance" Keywords: Southeast intermediation Insurance April 28, China Insurance IT veteran foreign service providers is still faith to be the number one domestic banking I

  • [Linux] lsof command and delete files under (Linux. Handle the problem of space released) 2010-07-01

    Introduction: First, the facts speak Second, on the other LSOF command usage: 3, reference documentation: Body: lsof: Finding open files with lsof Role: See what process the file is opened First, the facts speak Experimental] [Linux delete the file,

  • [Linux] lsof command and delete files under (Linux. Handle problems with the release of space) 2010-07-01

    Introduction: First, the facts speak Second, on the other LSOF command usage: 3, reference documentation: Body: lsof: Finding open files with lsof Role: See what process the file is opened First, the facts speak Experimental] [Linux delete the file,

  • Crontab command usage under Linux 2010-07-30

    In Linux, tasks can be configured in the specified time period, specified date, or the average system load below a specified number of hours automatically. Red Hat Enterprise Linux system pre-configured on the important task of running so the system

  • linux crontab command Detailed 2011-01-21

    This article describes the under linux cron (task scheduler) is commonly used methods. linux crontab format Basic format: * * * * * Command Time-moon week command Section 1 of minutes from 1 to 59 per minute with a * or * / 1 means that the first two

  • Crontab command using Linux system to achieve the scheduled reboot 2011-07-22

    Crontab is a very convenient in the unix / linux system timer (cycle) to perform a task of the program Use the cron service, use the cron service crond status check service status, if not start the service crond start to start it, cron service is a r

  • Detailed command and its use of Linux systems (Daquan) 2011-08-13

    Detailed command and its use of Linux systems cat cd chmod chown cp cut Name: cat Access: All users use: cat [-AbeEnstTuv] [- help] [- version] fileName Description: The connection string passed to the basic file output (screen or add> fileName to an

  • The use of crontab command in Linux 2011-01-29

    cron comes from the Greek word chronos (meaning "time"), is a linux system automatically performs the tasks assigned to the program. For example, you want to sleep during the night to create some of the backup file or folder, you can use cron to

  • Linux view the file and folder size command 2011-09-11

    Deployed on the server, multiple applications, suddenly found hard disk space usage reaches 76%, then use the df and du command to see the usage, found that many are caused to open the application log. df can view a folder size, using the ratio of fi

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.241 (s). 10 q(s)