1. Edit directly with crontab command
The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:
Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
CRONTAB-L//list details of a user cron service
Crontab-r//Delete a user's cron service
CRONTAB-E//Edit a user's cron service
For example, root to view your cron settings: Crontab-u root-l
Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
When editing the Cron service, the edited content has some formatting and conventions, input: Crontab-u root-e
Enter VI edit mode, the content of the edits must conform to the following format: */1 * * * * ls >>/tmp/ls.txt
The first part of this format is the time setting, the next part is the command to execute, if you want to execute too many commands, you can write these commands into a script, and then call this script directly here, you can recall the full path of the command when the call. Time setting we have a certain agreement, the preceding five * number represents five numbers, the value range and meaning of the numbers are as follows:
# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# | | .----------Day of Month (1-31)
# | | | .-------month (1-12) OR jan,feb,mar,apr ...
# | | | | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * * user-name command to be executed
In addition to the numbers there are several special symbols are "*", "/" and "-", ",", * represents all the values within the range of the number, "/" for each meaning, "*/5" means every 5 units, "-" represents from a number to a number, "," separate several discrete numbers. Here are a few examples to illustrate the problem:
Every morning at 6.
0 6 * * echo "Good morning." >>/tmp/test.txt//Note simply Echo, no output is visible from the screen, because cron emails any output to root.
Every two hours
0 */2 * * echo "has a break now." >>/tmp/test.txt
Every two hours between 11 o'clock and 8 in the morning, eight in the morning.
0 23-7/2,8 * * * echo "a good Dream:)" >>/tmp/test.txt
Every month, number 4th and Monday to Sunday, three a.m., 11.
0 4 * 1-3 command line
January 1 morning, 4.
0 4 1 1 * command line
[email protected] ~]# crontab-u root-e
* * * * reboot
[email protected] ~]# Service crontab Restart
Stop crond: [OK]
Starting crond: [OK]
[Email protected] ~]# crontab-u root-l
* * * * reboot
Daily 1 O'Clock 50 restart
You can also modify the/etc/crontab file, each time you finish editing a user's cron settings, Cron automatically generates a file with the same name as this user under/var/spool/cron, this user's cron information is recorded in this file, this file can not be directly edited, can only be edited with CRONTAB-E. After Cron starts, read the file once every one of the clocks, and check to see if you want to execute the command inside. Therefore, the Cron service does not need to be restarted after this file has been modified.
650) this.width=650; "title=" 6631900096001365638.jpg "src=" https://s2.51cto.com/wyfs02/M02/A5/48/ Wkiol1m6hqlibrl5aaajgllvxvu926.jpg-wh_500x0-wm_3-wmp_4-s_3822367025.jpg "alt=" Wkiol1m6hqlibrl5aaajgllvxvu926.jpg-wh_50 "/>
Mailto=root: Is it that when the/etc/crontab in this file is wrong, the error message or the message that is displayed on the screen is passed to whom? Because root and no longer user-side to receive the letter, therefore, I usually will this e-mail to my account, so that I always know the status of the system!
* * * * * root run-parts/etc/cron.hourly: In the #run-parts this line after the command, we can find that five digits followed by Root, this line represents the "level of execution as root" of course, You can also change this line into a different identity! The/etc/cron.hourly that run-parts represents is "all executables within a directory (/etc/cron.hourly)", that is, 01 points per hour, the system will be/etc/as root. Cron.hourly execute all executable files in this directory! The following three lines are also similar in meaning! You can go to the bottom of the/etc/to see, the system is originally preset these 4 directories! You can write the commands you need to execute every day directly to/etc/cron.daily, and you don't need to use the CRONTAB-E program!
This article is from the "Linux_woniu" blog, make sure to keep this source http://llu1314.blog.51cto.com/5925801/1965271
Linux in Crontab