Linux crontab command parameters and usage-linux automatic timing task cron

Source: Internet
Author: User

Linux crontab command parameters and usage-linux automatic timing task cron crontab command if you find that this command is not in your system, install the following two software packages. www.2cto.com vixie-cron crontabs 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 set the time table of the specified user. 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, the time table is set. Common parameters: crontab-l // view the cron task crontab-e under the current user // edit the current user's scheduled task crontab-u linuxso-e // edit the user's linuxso scheduled task usage and format: basic Format: *** command minute hour day month week command column www.2cto.com 1st represents minute 1 ~ 59 every minute, use * or */1 to indicate 2nd columns to indicate hour 1 ~ 23 (0 indicates 0 points) column 3rd indicates date 1 ~ 31 column 4th indicates the month 1 ~ 12 column ID No. 0 ~ 6 (0 indicates Sunday) some examples of the command crontab file to be run in column 6th: 30 21 ***/usr/local/etc/rc. d/lighttpd restart the above example indicates restarting apache at every night. 45 4, 22 **/usr/local/etc/rc. d/lighttpd restart the preceding example indicates restart apache on 4: 45 every month on day 1, 10, and 22. 10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart the example above indicates that apache is restarted at every Saturday and Sunday. The preceding example of-23 ***/usr/local/etc/rc. d/lighttpd restart indicates that apache is restarted every 30 minutes from to every day. 0 23 ** 6/usr/local/etc/rc. d/lighttpd restart the preceding example indicates that apache is restarted at every Saturday. Www.2cto.com **/1 ***/usr/local/etc/rc. d/lighttpd restart apache * 23-7/1 */usr/local/etc/rc every hour. d/lighttpd restart: restart apache 0 11 4 * mon-wed/usr/local/etc/rc every hour from. d/lighttpd restart: restart apache 0 4 1 jan */usr/local/etc/rc from every Monday to Wednesday. d/lighttpd restart apache name: crontab usage permission: All users use crontab file [-u user]-use the specified file to replace the current crontab. 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. www.2cto.com 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. The shell only contains three environment variables: USER, HOME, and SHELL: 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 set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If you do not use-u user, it indicates that you have set your own time table at www.2cto.com. Parameter: 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, first, set the VISUAL environment variable to specify the Text Editor (for example, setenv VISUAL joe) crontab-r: Delete the current time table crontab-l: 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 where f1 represents minutes, f2 represents hours, f3 represents the day of a month, and f4 represents the month, f5 indicates the day of the week. Program indicates the program to be executed. When f1 is *, the program is executed every minute. If f2 is *, the program is executed every hour, and so on. When f1 is a-B, it indicates that it will be executed from minute a to minute B, when f2 is a-B, it indicates that execution is performed from hour a to hour B, and so on. When f1 is */n, it indicates that execution is performed every n minutes, if f2 is */n, the task is executed every n hours. Similarly, when f1 is a, B, c ,... a, B, c ,... execute in minutes. f2 is a, B, c ,... a, B, c... you can save all settings in the file and use crontab file to set the time table. Example: ● 0 */2 ***/sbin/service httpd restart means to restart apache every two hours ● 50 7 ***/sbin/service sshd start means to enable ssh at every day service ● 50 22 ***/sbin/service sshd stop means to close the ssh service at every day ● 0 0 ** fsck/home checks/home disks on the 1st and 15th of every month ● 1 ***/home/bruce/backup execute the file at the first point of every hour/home/bruce/backup ●00 03 ** 1-5 find/home "*. xxx "-mtime + 4-exec rm {}/; every Monday to Friday three o'clock, in the directory/home, find the file name *. xxx file, and delete the file four days ago. ● 30 6 */10 ** ls means to execute the ls command www.2cto.com at on the first, 11th, 21st, and 31st of every month # execute/bin/ls at every morning: 0 7 */bin/ls: Execute/usr/bin/backup once every three hours from to every day within January 1, December: 0 6-12/3*12 */usr/bin/backup from Monday to Friday send a letter to alex@domain.name at every day: 0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata every day at midnight 00:20, 02:20, 04:20 .... run echo "haha" 20 0-23/2 *** echo "haha" www.2cto.com. Note: When the program is executed at the specified time, the system will send you a letter, display the content of the program execution. If you do not want to receive such a message, add>/dev/null 2> & 1 after each line with an empty box to 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 www.2cto.com # every month and am from Monday to wed every week 4 * mon-wed date # Am of July 4 1 jan * date example $ crontab-l list the current crontab of a user. this article is from the Linux Security Network

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.