Linux crontab timer and linuxcrontab Timer

Source: Internet
Author: User

Linux crontab timer and linuxcrontab Timer

Crontab parameters:

-U: helps other users create or remove work schedules.

-L: view the work content of crontab

-R: removes all crontab work content.

-E: edit the crontab file.

Each job has six fields:

******

Minute Hour Date month week instruction

0-59 0-23 1-31 1-12 0-7 instructions #0 and 7 indicate Sunday

Auxiliary special characters:

* Represents any time

, Indicates the split time. For example, and are.

-Represents a period of time. For example, 2 to 5 is 2-5.

/N indicates a number, that is, every n units. Such as every 5 minutes,/5

Example: send an email to the pc at every Wednesday.

30 14 ** 3 mail pc-s "test" & lt;/home/text.txt

To edit system routine tasks, you can edit the/etc/crontab file

 

Basic Format:
* *** Command
Hour, day, month, and week commands
The 1st column indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
6th columns of commands to run


Some examples of crontab files:
30 21 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting apache at every night.
45 4, 10, 22 **/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at on the 1st, 10th, and 22th every month.
10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday and Sunday.
0, 30 18-23 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted every 30 minutes between and every day.
0 23 ** 6/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday.
**/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart apache every hour
* 23-7/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart apache every hour between PM and PM.
0 11 4 * mon-wed/usr/local/etc/rc. d/lighttpd restart
Restart apache on November 4 and every Monday to Wednesday.
0 4 1 jan */usr/local/etc/rc. d/lighttpd restart
Restart apache at on January 1, January 1
Name: crontab
Permission: All Users
Usage:
Crontab file [-u user]-replace the current crontab with the specified file.
Crontab-[-u user]-replace the current crontab with the standard input.
Crontab-1 [user]-list the current crontab of the user.
Crontab-e [user]-edit the current crontab of the user.
Crontab-d [user]-delete the current crontab of the user.
Crontab-c dir-specifies the crontab directory.
Crontab file format: m h d m d cmd.
M: minute (0-59 ).
H: hour (0-23 ).
D: Day (1-31 ).
M: Month (1-12 ).
D: days in a week (0 ~ 6, 0 is Sunday ).
The program to run in cmd is sent to sh for execution. This shell only contains three environment variables: USER, HOME, and SHELL.
Note:
Crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to specify
The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, it indicates
Set your own time table.
Parameters:
Crontab-e: run the text editor to set the time table. The preset text editor is VI. If you want to use another text editor, set the VISUAL environment variable first.
To specify the Text Editor (for example, setenv VISUAL joe)
Crontab-r: Delete the current time table
Crontab-l: to list the current time table
Crontab file [-u user]-replace the current crontab with the specified file.
The time table format is as follows:
F1 f2 f3 f4 f5 program
F1 indicates the minute, f2 indicates the hour, f3 indicates the day of the month, f4 indicates the month, and f5 indicates the day of the week. Program indicates to execute
.
When f1 is *, the program is executed every minute. When f2 is *, the program is executed every hour, and so on.
When f1 is a-B, it indicates that execution is performed from the minute a to the minute B. When f2 is a-B, it indicates that execution is performed from the hour a to the hour B, and so on
When f1 is */n, it indicates execution is performed every n minutes. If f2 is */n, it indicates execution is performed every n hours, and so on.
When f1 is a, B, c ,... a, B, c ,... execute in minutes. f2 is a, B, c ,... a, B, c... execution in hours, and so on
You can also store all settings in the file first, and use crontab file to set the time table.
Example:
# Run/bin/ls at every morning:
0 7 ***/bin/ls
During October 11, December, execute/usr/bin/backup every three hours from to every day:
0 6-12/3*12 */usr/bin/backup
From Monday to Friday, send a letter to alex@domain.name at pm:
0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata
Execute echo "haha" at midnight, 00:20, and 02:20 every month"
20 0-23/2 *** echo "haha"
Note:
When the program is executed at the specified time, the system will send you a letter showing the program execution content. If you do not want to receive such a letter, please leave each row Blank
Add>/dev/null 2> & 1.
Example 2:
#06:10 every morning
10 6 **** date
# Every two hours
0 */2 * date
# Every two hours from PM to am, am
0 23-7/2, 8 **** date
# Am on the 4th day of each month and from Monday to Wednesday of each week
0 11 4 * mon-wed date
# A.m. of July
0 4 1 jan * date
Example
$ Crontab-l list the current crontab of a user.

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.