linux-Install timing plug-in crontab

Source: Internet
Author: User

  1. Installing crontab
    [email protected] ~]# Yum install-y vixie-cronloaded plugins:securitybase| 3.7 KB 00:00Epel| 4.3 KB 00:00Epel/primary_db | 5.9 MB 00:05Extras| 3.4 KB 00:00Updates| 3.4 KB 00:00Updates/primary_db | 2.0 MB 00:01Setting up Install processresolving Dependencies-Running Transaction Check---> Package cronie.x86_64 0:1.4.4-16.el6_8.2Would be installed-Processing Dependency:dailyjobs for  Package: cronie-1.4.4-16.el6_8.2. x86_64--Processing Dependency:/usr/sbin/sendmail for  Package: cronie-1.4.4-16.el6_8.2. x86_64-Running Transaction Check---> Package cronie-anacron.x86_64 0:1.4.4-16.el6_8.2Would be installed-Processing Dependency:crontabs for  Package: cronie-anacron-1.4.4-16.el6_8.2. x86_64---> Package exim.x86_64 0:4.84.2-3. El6 'll be installed-Running Transaction Check---> Package crontabs.noarch 0:1.10-33. El6 'll be installed-finished Dependency resolutiondependencies resolved================================================================================Package Arch Version Repository Size================================================================================Installing:cronie x86_641.4.4-16.el6_8.2 Updates 75kinstalling forDependencies:cronie-anacron x86_64 1.4.4-16.el6_8.2 Updates 31k crontabs Noarch1.10-33.EL6 base 10k Exim x86_644.84.2-3.EL6 Epel 1.3mtransaction Summary================================================================================Install4Package (s) Total Download size:1.4minstalled Size:4.2mdownloading Packages: (Quarter): cronie-1.4.4-16.el6_8.2.x86_64.rpm | KB 00:00(2/4): cronie-anacron-1.4.4-16.el6_8.2.x86_64.rpm | KB 00:00(3/4): crontabs-1.10-33.el6.noarch.rpm | Ten KB 00:00(4/4): exim-4.84.2-3.el6.x86_64.rpm | 1.3 MB 00:01-------------------------------------------------------------------------------- Total1.0 MB/s | 1.4 MB 00:01Running rpm_check_debugrunning Transaction testtransaction Test succeededrunning Transaction Installing:exim-4.84.2-3.el6.x86_64 1/4Installing:cronie-1.4.4-16.el6_8.2.x86_64 2/4Installing:crontabs-1.10-33.el6.noarch 3/4Installing:cronie-anacron-1.4.4-16.el6_8.2.x86_64 4/4Verifying:crontabs-1.10-33.el6.noarch 1/4Verifying:cronie-anacron-1.4.4-16.el6_8.2.x86_64 2/4Verifying:exim-4.84.2-3.el6.x86_64 3/4Verifying:cronie-1.4.4-16.el6_8.2.x86_64 4/4Installed:cronie.x86_640:1.4.4-16.el6_8.2Dependency Installed:cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 Crontabs.noarch 0:1.10-33. El6 exim.x86_640:4.84.2-3. El6complete!
  2. Whether to set the power on self-boot
    Chkconfig--list Crond
  3. Start crontab
    [Email protected] ~]# service Crond startstarting crond:                                            [  OK  ]
  4. The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:

    Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
    CRONTAB-L//list details of a user cron service
    Crontab-r//Delete a cron service with no users
    CRONTAB-E//Edit a user's cron service

  5. Crontab Adding timing

Basic format:
* * * * * command
Time-sharing Weekly 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
Some examples of crontab files:
* * * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that 21:30 restarts Apache per night.
4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.
1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.
0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows the restart of Apache every Saturday at 11:00am.
* */1 * * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour
* 23-7/1 * * * */usr/local/etc/rc.d/lighttpd restart
From 11 o'clock to 7 in the morning, restart Apache every hour.
0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart
4th per month with 11-point restart from Monday to Wednesday Apache
0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart
4-point restart of Apache on January 1
Name: crontab
Usage rights: All users
How to use:
crontab file [-u user]-replaces the current crontab with the specified files.
Crontab-[-u user]-replaces the current crontab with standard input.
crontab-1[user]-lists the user's current crontab.
crontab-e[user]-Edit user's current crontab.
crontab-d[user]-Delete the user's current crontab.
Crontab-c dir-Specifies the directory for crontab.
Format of the crontab file: M H d M D cmd.
M: Minutes (0-59).
H: Hours (0-23).
D: Day (1-31).
M: Month (1-12).
D: Day of the Week (0~6,0 is Sunday).
CMD to run the program, the program is fed into sh execution, this shell only user,home,shell these three environment variables
Description
Crontab is used to allow a user to execute a program at a fixed time or at a fixed interval, in other words, a user-like schedule. -u user refers to setting the specified
User's time table, which presupposes that you must have permission (for example, root) to specify another's time schedule. If you do not use the-u user, it means to set the
Set your own schedule.
Parameters:
CRONTAB-E: Do a text editor to set the time table, the default text editor is VI, if you want to use another text editor, please set the VISUAL environment variables first
To specify the use of that text editor (for example, Setenv VISUAL Joe)
Crontab-r: Delete the current schedule table
Crontab-l: List the current schedule
crontab file [-u user]-replaces the current crontab with the specified files.
The format of the schedule table is as follows:
F1 F2 F3 f4 f5 program
Where F1 is expressed in minutes, F2 represents hours, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. program says
The program of the line.
When F1 is * indicates that every minute the program,f2 is executed, the program is executed every hour, and the remainder of the analogy
When the F1 is a-B, it is executed from the time of the minute to the minute of the hour, and the F2 is a-B indicating that it is executed from the first to the first, and the remainder of the analogy
When F1 is */n, it is performed once every n minutes, and F2 is */n for every n-hour interval, with the remainder of the other analogy
When F1 is a, B, C,... A, B, C,... Minutes to execute, F2 for a, B, C,... The time indicated that the first, B, c ... Hours to execute, and the rest of the analogy
The user can also store all the settings in the file file, using the crontab file to set the time schedule.
Example:
#每天早上7点执行一次/bin/ls:
0 7 * * */BIN/LS
In December, the/usr/bin/backup is performed every 3 hours in the morning from 6 to 12.
0 6-12/3 */usr/bin/backup
Monday to Friday every 5:00 send a letter to [email protected]:
0 * * 1-5 mail-s "HI" [email protected] </tmp/maildata
Every day of the month 0:20 midnight, 2:20, 4:20 .... Perform echo "haha"
0-23/2 * * * echo "haha"
Attention:
When the program is executed at the time you specify, the system will send you a letter showing what the program is doing, and if you do not wish to receive such a letter, please leave a blank in each line
After adding >/dev/null 2>&1 can be
Example 2:
#每天早上6点10分
6 * * */home/st.sh
#每两个小时
0 */2 * * */home/st.sh
#晚上11点到早上8点之间每两个小时, 8 in the morning.
0 23-7/2,8 * * */home/st.sh
#每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
0 4 * mon-wed/home/st.sh
#1月份日早上4点
0 4 1 Jan */home/st.sh

linux-Install timing plug-in crontab

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.