Scheduled task execution commands in Linux

Source: Internet
Author: User

In Linux, after the scheduled task execution command has the mail alarm function, the next step is to make a scheduled task for periodic execution of this task, in this way, you can receive the alarm information periodically. Before doing a scheduled task, check the current system time [date "+ % Y-% m-% d % T"] and hardware clock time [hwclock ]: [root @ localhost test] # date "+ % Y-% m-% d % T" 2013-07-01 07:57:52 [root @ localhost test] # hwclock on Monday 1, July 01, 2013-48 seconds- 0.059059 the results above seconds show that, my current clock time is incorrect. Set the system time first: [root @ localhost test] # date-s "July 09, 2013 08:47:00" 08:47:00 CST reset hardware time and system time synchronization [root @ localhost test] # hwclock-w next to view system time and hardware clock time: [root @ localhost test] # hwcl Ock 08:47:13-0.180411 seconds [root @ localhost test] # date "+ % Y-% m-% d % T" July 09, 2013 [root @ localhost test] # The time is normal, now we can do the scheduled task. In Linux, it is relatively simple to do the scheduled task. You can use the crontab command. Edit a test. sh. The content is formatted to display the current system time: date "+ % Y-% m-% d % T". Run the following command to view the result: [zl @ localhost test] $ sh test. sh2013-07-09 09:03:28 good, the result is normal. The following is a brief introduction to the crontab command: common parameters: crontab-l // view the cron task crontab-e under the current user // edit the current user's scheduled task [zl @ localhost test] $ crontab-l52 8 *** sh/home /zl/test. sh>/home/zl/test/test_chrontab.txt indicates that my current user has a scheduled task. Let's analyze this scheduled task: 52 8 *** sh/home/zl/test. sh> The/home/zl/test/test_chrontab.txt task is divided into six parts, abstracted as the hour, month, and week command ***** command column 1st indicates 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). For example, run the preceding command in the 6th column. The task is executed at 08:52 every day and the command is sh/home/zl/test. sh>/home/zl/test/test_chrontab.txt if we need to add another weekly report task at every Friday, then run crontab-e [run the text editor to set the time table, and the preset text editor is vi]. Add 50 23 ** 5 sh/home/zl/weekly_report.sh to the task: [zl @ localhost test] $ crontab-ecrontab: installing new crontab: view the task list again, A new task [zl @ localhost test] $ crontab-l52 8 *** sh/home/zl/test is added. sh>/home/zl/test/tes T_chrontab.txt50 23 ** 5 sh/home/zl/weekly_report.sh [zl @ localhost test] $ here are some examples used by others: 0 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. **/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 at on January 1, January 1

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.