Deep analysis of the timing tasks under Linux _unix Linux

Source: Internet
Author: User

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
July 01, 2013 Monday 07:57 48 sec -0.059059 seconds

The above results show that my current clock time is incorrect, set the system time first:
[Root@localhost test]# date-s "2013-07-09 08:47:00"
July 09, 2013 Tuesday 08:47:00 CST

Set hardware time and system time synchronization again
[Root@localhost test]# hwclock-w

Check the system time and hardware clock time below:

[Root@localhost test]# Hwclock
July 09, 2013 Tuesday 08:47 07 sec -0.180411 seconds
[Root@localhost test]# Date "+%y-%m-%d%T"
2013-07-09 08:47:13
[Root@localhost test]#

Time is normal, the following can do the scheduled task, in Linux to do the timing task is relatively simple, using the crontab command can be. To facilitate viewing of the effect, first edit a test.sh that formats the current system time:

Date "+%y-%m-%d%T"

Perform a review of the results:

[Zl@localhost test]$ SH test.sh
2013-07-09 09:03:28

Well, the result is normal. Here's a simple learning crontab command:

Common parameters:
Crontab-l//view cron tasks under current user
CRONTAB-E//Edit the current user's timed task

[Zl@localhost test]$ Crontab-l
8 * * * sh/home/zl/test/test.sh >>/home/zl/test/test_chrontab.txt

Description of my current user, there is a timed task, let's analyze This timed task:

8 * * * sh/home/zl/test/test.sh >>/home/zl/test/test_chrontab.txt

The task is divided into 6 parts, abstracted out for

Time-sharing and Lunar Week command

* * * * command

The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 for 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
The 5th list of the week 0~6 (0 for Sunday)
6th column the command to run

Take the above example, the task is executed at 8:52 every day, the execution of the command for sh/home/zl/test/test.sh >>/home/zl/test/test_chrontab.txt

If we need to add another weekly report every Friday 23:50, then

Execute Crontab-e "Execute text editor to set the time table, the default text editor is VI", add a * * 5 sh/home/zl/weekly_report.sh in the task:

[Zl@localhost test]$ crontab-e
Crontab:installing New Crontab

Look at the task list again and add a new task
[Zl@localhost test]$ crontab-l
8 * * * sh/home/zl/test/test.sh >>/home/zl/test/test_chrontab.txt
* * 5 sh/home/zl/weekly_report.sh
[Zl@localhost test]$

The

below is accompanied by some other examples:

0 * * */usr/local/etc/rc.d/lighttpd Restart
The example above shows 21 per night : 30 restart Apache.

4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD Restart
The above example indicates 1, 10, 22nd 4:45 restart Apache. The example above,

1 * * 6,0/usr/local/etc/rc.d/lighttpd restart
, represents 1:10 restart Apache per Saturday and Sunday.

0,30 18-23 * * */usr/local/etc/rc.d/lighttpd Restart
The above example indicates that Apache is restarted every 30 minutes from 18:00 to 23:00 every day.

0 * * * 6/usr/local/etc/rc.d/lighttpd Restart
The example above indicates that the 11:00 PM restarts Apache every Saturday.

* */1 * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour

* 23-7/1 * * */USR/LOCAL/ETC/RC.D/LIGHTT PD Restart
11 o'clock to 7 a.m., every hour to restart Apache

0-4 * mon-wed/usr/local/etc/rc.d/lighttpd Restart
Monthly number 4th and every Monday to Wednesday 11 points to restart the Apache

0 4 1/usr/local/etc/rc.d/lighttpd * Restart
January 1 4 point restart Apache

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.