Detailed and sample crontab in Linux (collection)

sponsored links
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
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Detailed and sample crontab in Linux (collection)

  • js page Jump implementation of a number of ways

    The first is: <script language="javascript" type="text/javascript"> window.location.href = "login.jsp? backurl =" + window.location.href; </ script> The second: <script language="javascript"> alert

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • Dynamic loading JS script four kinds of methods

    To achieve dynamic loading JS script has four kinds of methods: 1, direct document.write <script language="javascript"> document.write ( "<script src='test.js'> <\ / script>"); </ script> 2, dynamic scri

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • Hibernate pessimistic locking mechanism for locking and optimistic locking

    hibernate lock mechanism 1. Pessimistic lock It refers to the modification of data by outsiders hold a conservative attitude. The assumption that at any time access to data, may also have another client to access the same data, in order to maintain t ...

  • Ruby on Rails Routing - Simple Examples

    This article contains a list of ruby on rails routing examples. If you find you have any questions please leave a comment. Routes are processed from the top of routes.rb down. If a route is matched it will stop processing the routes.rb file and use that r

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries