Deep analysis of the timing tasks under Linux

Source: Internet
Author: User
After having the alarm function of the mail, the next thing to do is to do a timed task, so that the task is performed on a periodic basis, so that it can periodically receive the alarm information

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< /c10>

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 that others use:

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

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/li ghttpd Restart
11 o'clock to 7 in the morning, every hour to restart the Apache

0-4 * mon-wed/usr/local/etc/rc.d/lighttpd Restart
Monthly 4th and Weekly Restart Apache

0 4 1/usr/local/etc/rc.d/lighttpd restart
January 1 4 o ' Back to Wednesday

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.