/*************************************** ******************************
* Author: Samson
* Date: 08/08/2012
* Test Platform:
* GNU Linux version 2.6.29.4
* GCC version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC)
**************************************** ****************************/
Crontab is used to allow users to run 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.
Parameters:
-E [username]: run the text editor to set the time table. The preset text editor is vi. If you want to use another text editor, set the visual environment variable to specify the Text Editor (for example, setenv visual Joe)
-R [username]: deletes the current time table.
-L [username]: list the current time series table
-V [username]: lists the statuses of user cron jobs.
Basic Format:
* *** Command
Hour, day, month, and week commands
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
Example:
For example, if you execute a shell file every two minutes, use:
Crontab-e open the configuration file and enter:
*/2 *****/home/Samson/crontabtest/test. Sh
Every two hours:
**/2 *** shellprogram_name
Others.
Note:/home/Samson/crontabtest/test. Sh must have executable permissions.
After the configuration is complete, save and execute:
/Etc/init. d/crond restart or service crond restart
Restart to make the new entry take effect.
The content of/home/Samson/crontabtest/test. Sh is:
#! /Bin/bash
Datetime = 'date'
Echo-e "write time is $ {datetime} \ n" >>/ home/Samson/yygydjtkhhh
Echo-e "this is crontab test">/home/Samson/yygydjtkhhh
Echo-e "End \ n">/home/Samson/yygydjtkhhh
Then we can view:
[Root @ UFO crontabtest] # Cat/home/Samson/yygydjtkhhh
Write time is Thu Aug 9 09:32:01 CST 2012
This is crontab Test
End
Write time is Thu Aug 9 09:34:01 CST 2012
This is crontab Test
End