Timed synchronization of time to NTP service and logging
First, create a log file:
[[Email protected] ~] #touch/var/log/upclock.log//Create update log file
[[Email protected] ~] #chmod 740/var/log/upclock.log//Modify Permissions
[[Email protected] ~] #crontab-E//Edit root user default crontab
Enter the following command:
0 * * 0 ntpdate cn.pool.ntp.org >>/var/log/upclock.log
This means that every Sunday night 23 o'clock Sync time, save is OK. -----------------------------------------------------------------------------------------------
crontab Format*****task * numbers are arranged in order, respectively, representingFirst, create a log file:
First * 0-59 minutesSecond * 1-23 hoursThird * 1-31 daysFourth star * January-DecemberFifth * 0-6 weeks (0 = Sunday)the task represents the action to be performed such as Ntpdate 10.1.0.41
Some examples:
21* * */apps/bin/cleanup.sh
The above example shows that 2 1:3 0 per night run/a p p s/b i n the directory C l e a n u p. S H.
4 1,10,22 * */apps/bin/backup.sh
The above example shows that the 1, 1 0, 2 2nd of the 4:4 5 run/A p p s/b i n directory b a c K U p. S H.
1 * * 6,0/bin/find-name "core"-exec rm {};
The above example shows that 1:1 0 per Saturday, Sunday runs an f i n d command.
0,30 18-23 * * */apps/bin/dbcheck.sh
The above example shows the D b c h e c K in the 1 8:0 0 to 2 3:0 0 run every 3 minutes/a p p s/b i n directory. S H.
0 * * 6/apps/bin/qtrend.sh
The above example shows the 11:0 0 p m running per Saturday/a p p s/b i n directory of q t r e N d. S h
Two ways to implement timed tasks
One is to edit a file and load it with crontab
One is to use CRONTAB-E direct editing to take effect
Example:
Enter a bunch of characters in a file every minute
First VI CRONTAB1
#every minute echo Char to file
1-59 * * * * echo ' date ' "MySQL" >>/opt/shuju/dazi.txt
Better Add a comment
So you can define the purpose of the current scheduled task.
Then crontab crontab1 load CRONTAB1 This timed task
The other one is
Crontab-e
#every minute echo Char to file
1-59 * * * * echo ' date ' "Tian" >>/opt/shuju/da.txt
Date in single quotation marks, which means that if date is a command, it executes as a command.
If you use date directly, then the output is the string "date", not the result of the date command.
>> is attached to the end of the file, and > is directly overwriting the file
If Crontab-e cannot edit
So your environment variable is not configured
Please enter Vi/etc/profile.
Plus
Editor=vi
Export EDITOR
Crontab-l List all scheduled tasks if you want to delete a scheduled task
So
Crontab-e
Comment out the corresponding timed task statement
For example, to delete the scheduled task that I just defined
#every minute echo Char to file
1-59 * * * * echo ' date ' "Oracle" >>/opt/shuju/tj.txt
only need
#every minute echo Char to file
#1 -59 * * * * echo ' date ' "Oracle" >>/opt/shuju/tj.txt
If you use Crontab-r
Remove all scheduled tasks (requires special care)
In more detail in the http://www.cnblogs.com/tracy/archive/2011/12/27/2303788.html
Linux timed Tasks