With the mail alarm function, the next step is to create a scheduled task to run the task on a periodic basis, so that the alarm information can be periodically received.
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
Monday July 01, 2013-48 seconds-0.059059 seconds
The above results show that my current clock time is incorrect. Set the system time first:
[Root @ localhost test] # date-s "08:47:00"
Tuesday, July 09, 2013 08:47:00 CST
Set the hardware time and system time synchronization.
[Root @ localhost test] # hwclock-W
Next, view the system time and hardware clock time:
[Root @ localhost test] # hwclock
Tuesday July 09, 2013-0.180411 seconds
[Root @ localhost test] # date "+ % Y-% m-% d % t"
2013-07-09 08:47:13
[Root @ localhost test] #
After the time is normal, you can perform the scheduled task below. In Linux, it is relatively simple to perform the scheduled task. You can use the crontab command. To make it easier to view the effect, edit a test. Sh file. The content is to format and display the current system time:
Date "+ % Y-% m-% d % t"
Run the following command to view the result:
[ZL @ localhost test] $ sh test. Sh
2013-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 cron tasks of the current user
Crontab-E // edit the scheduled task of the current user
[ZL @ localhost test] $ crontab-l
52 8 *** sh/home/ZL/test. Sh>/home/ZL/test/test_chrontab.txt
It indicates that my current user has a scheduled task. Let's analyze this scheduled task:
52 8
* ** Sh/home/ZL/test. Sh>/home/ZL/test/test_chrontab.txt
The task is divided into six parts, abstracted
Hour, day, month, and week commands
* *** Command
The 1st column indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
6th columns of commands to run
The preceding example shows that the task is executed at 08:52 every day. 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
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-e
Crontab: Installing new crontab
View the task list again and add a new task.
[ZL @ localhost test] $ crontab-l
52 8 *** sh/home/ZL/test. Sh>/home/ZL/test/test_chrontab.txt
50 23 ** 5 sh/home/ZL/weekly_report.sh
[ZL @ localhost test] $
The following are examples used by others:
0 21 ***/usr/local/etc/rc. d/Lighttpd restart
The preceding example indicates restarting Apache at every night.
45 4, 10, 22 **/usr/local/etc/rc. d/Lighttpd restart
The preceding example indicates that Apache is restarted at on the 1st, 10th, and 22th every month.
10 1 ** 6, 0/usr/local/etc/rc. d/Lighttpd restart
The preceding example indicates that Apache is restarted at every Saturday and Sunday.
0, 30 18-23 ***/usr/local/etc/rc. d/Lighttpd restart
The preceding example indicates that Apache is restarted every 30 minutes between and 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
Restart Apache every hour
* 23-7/1 ***/usr/local/etc/rc. d/Lighttpd restart
Restart Apache every hour between PM and PM.
0 11 4 * Mon-wed/usr/local/etc/rc. d/Lighttpd restart
Restart Apache on November 4 and every Monday to Wednesday.
0 4 1 Jan */usr/local/etc/rc. d/Lighttpd restart
Restart Apache at on January 1, January 1