cron service

As opposed to at, cron advantage is the ability to periodically execute a command, at it only once, the name of the cron daemon crond, cron is the system V of service, so we can service crond start | stop and start turn off this service, you can also use chkconfig or ntsysv to select the default cron service is turned on, these commands before we have talked about

  command:

  #crontab -e to edit the current user's cron table

#crontab -l to view the current user's cron table

#crontab -r delete the current user cron process

#crontab -u user name in as a user to control the cron table

There are important knowledge point, is that when the user is located in a scheduled task to establish var / spool / cron directory

When using crontab -e to edit the current user cron table, there will be a vi file, cron format is this. Divided into two, the left is the time, the right is the command to run. Time is 5 parts.

Example:

* * * * *          wall hello everyone

5 asterisks represent: minute hour day-of-month month-of-year day-of-week, and the wall hello everyone this is the content of the command. Consciousness is above daily weekly monthly broadcast hello everyone every minute every hour. The specific time you can define your own. If you want to use every two minutes transmitted * / a * 2 instead of the first. It may be represented by a specific time.

We use crontab -e to edit the current user's cron table

Here are five stars on the time and date on behalf of:

The first few minutes * asterisk represents the first hour: minute range is from 0-59

The second * The asterisk represents the first of several hours each day: hour range from 0-23

The first few days * asterisk represents the third of each month: day-of-month range from 1-31

* Asterisk represents the fourth year did the first few months: month-of-year range from 1-12

* The asterisk represents the fifth week of the week: day-of-week range from 0-6, with 0 representing Sunday

Username: is the implementation of a program to be executed by which user, this can generally be omitted;

Command: execution of commands and parameters.

When the schedule is formatted as follows:

f1 f2 f3 f4 f5 program

Where f1 is a minute, f2 for hours, f3 represents a month in the first few days, f4 represents the month, f5 represents the day of the week. program represents a program to be executed.

When expressed as f1 * indicates every hour during the implementation of the program to be executed per minute program, f2 for the * rest so

Represents the first to be executed from within a minute to a minute of the period b, f2 is represented to be performed ab from a to b hours of rest so when f1 is ab

When expressed as f1 * / n n per one minute time intervals, f2 is * / n n represent each one hour time intervals, so the remaining

Denotes a, b, c ... when f1 is a, b, c, ... represents when a, b, c, ... minutes to perform, f2 is a, b, c, ... hours to perform, so the rest

Users can also set all of the files stored in the first file in the way with crontab file to set the time-table.

  Example 1: If I want to express Sept. 10 execution 25 points ls var / spool / cron task of how to express?

25 × 10 9 * ls var / spool / cron

Because I did for hours, so we can only inside per hour

  Example 2: I want every Sunday, the command execution wall Hello redking.blog.51cto.com per minute, time how representation?

*/1 * * * 0 wall Hello redking.blog.51cto.com

* /   Represents how many minutes per execution

  Example 3: night 21:30 restart apache.

30 21 * * * /usr/local/etc/rc.d/lighttpd restart

  Example 4: 1 month, 10, 22, the 4:45 restart apache

        45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart

Example 5: every Saturday and Sunday 1:10 to restart apache

    10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart

Example 6: day 18: 00-23: 00 every 30 minutes restart apache

    0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart

Example 7: every hour restart apache

    * */1 * * * /usr/local/etc/rc.d/lighttpd restart

Example 8: between 11 pm to 7 am, every hour restart apache

    * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart

Example 9: Monthly No. 4 and 11:00 from Monday to Wednesday to restart apache

    0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart

Example 10: 1 January of 4:00 to restart apache

    0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart

Example 11: In 12 months, 6 to 12 o'clock in the morning every day, every three hours to perform a / usr / bin / backup

    0 6-12/3 * 12 * /usr/bin/backup

Example 12: month every day at midnight 0:20, 2:20, 4:20 .... performing echo "haha"

    20 0-23/2 * * * echo "haha"

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11109424.html