Configuration File VI/etc/crontab
Set file VI/etc/crontab
1st columns minute 1 ~ 59
2nd columns hour 1 ~ 23 (0 indicates midnight)
1-3rd ~ 31
4th columns Month 1 ~ 12
5th columns in a week 0 ~ 6 (0 indicates Sunday)
6th columns of commands to run
The following is the crontab format:
Command to be run by hour, day, month, and week
Here are some examples of crontab file entries:
30 21 ***/usr/local/Apache/bin/apachectl restart
The preceding example indicates restarting Apache at every night.
45 4, 22 **/usr/local/Apache/bin/apachectl restart
The preceding example indicates that Apache is restarted at on the 1st, 10th, and 22th every month.
10 1 ** 6, 0/usr/local/Apache/bin/apachectl restart
The preceding example indicates that Apache is restarted at every Saturday and Sunday.
0, 30 18-23 ***/usr/local/Apache/bin/apachectl restart
The preceding example indicates that Apache is restarted every 30 minutes between and every day.
0 23 ** 6/usr/local/Apache/bin/apachectl restart
The preceding example indicates that Apache is restarted at every Saturday.
**/1 ***/usr/local/Apache/bin/apachectl restart
Restart Apache every hour
* 23-7/1 ***/usr/local/Apache/bin/apachectl restart
Restart Apache every hour between PM and PM.
0 11 4 * Mon-wed/usr/local/Apache/bin/apachectl restart
Restart Apache on November 4 and every Monday to Wednesday.
0 4 1 Jan */usr/local/Apache/bin/apachectl restart
Restart Apache at on January 1, January 1
If you want to run some complex commands or multiple commands, you can write them as shell to run them.
Crontab-E is designed for the user's cron. What should we do if it is a routine task of the system? Do you still need to use crontab-e to manage routine commands? No, you only need to edit the/etc/crontab file. It should be noted that the role of crontab-E is actually the execution file/usr/bin/crontab, but/etc/crontab is a plain text file, you can edit this file as root.
Basically, the minimum detection time unit of the cron service is minute. Therefore, cron reads data in/etc/crontab and/var/spool/cron every minute. Therefore, after the/etc/crontab file is edited and saved, the crontab settings are automatically executed.
Note: crontab in Linux will automatically help us read the routine work items of/etc/crontab every minute, but for some reason or in other UNIX systems, since crontab is read to the memory, it may not be executed immediately after you modify/etc/crontab. Restart the crond service.
/Etc/rc. d/init. d/crond restart
Now let's take a look at the content of the/etc/crontab file:
VI/etc/crontab
Shell =/bin/bash
Path =/sbin:/bin:/usr/sbin:/usr/bin
Mailto = root
Home =/
# Run-Parts
01 *** root nice-N 19 run-parts/etc/cron. Hourly
02 4 *** root nice-N 19 run-parts/etc/cron. daily
22 4 *** root nice-N 19 run-parts/etc/cron. Weekly
42 4 1 ** root nice-N 19 run-parts/etc/cron. Monthly
Time-sharing, day-month-week, user parameter setting value, parameter setting value, instruction segment
From the content of this file, we can see that the content of this file is almost the same as that of the input crontab-e, but the following are some differences:
• Mailto = root: this field indicates who will pass the error message or information displayed on the screen when a regular command in the/etc/crontab file is incorrect? Because root cannot receive emails on the client, you can change this email to your normal user account.
• 01 *** root nice-N 19 run-parts/etc/cron. hourly: The command after the # Run-parts line shows that the five numbers are followed by root, which indicates that the execution level is root. Of course, you can also change the root to another identity, while run-parts indicates that/etc/cron is followed. hourly is a directory (/etc/cron. all executable files in hourly), that is to say, every hour's, the system will be root to/etc/cron. execute all executable files in the hourly directory. By default, the system has these four directories. You can directly write the commands to be executed every day to/etc/cron. daily without using crontab.
-E program, very convenient.
Note: basically,/etc/crontab supports two ways to input commands. One is to input commands directly, and the other is to input commands as directories.
Command form
01 *** test mail-s test The user is test and the command mail is executed hourly ......
Directory format
*/5 * root run-parts/root/runcron
Create a/root/runcron directory to write the executable files that are executed every 5 minutes to this directory, the system can execute all executable files in the directory every five minutes.
In this way, you will know the role of Run-parts! In addition, unlike crontab-E, a user-level concept is added. Generally, we plan routine commands from the root perspective, but there is always a need for root, so we can use this level to standardize the user ownership of the program.
If each process is started at the same time, the system will be very busy during a certain period of time, so you must set them separately. You can do this:
, **** Root ............ // Ellipsis represents a command
, * Root ............
, Root ............
, **** Root ............
Note: do not contain spaces when you separate them with commas. In this way, the workflow of every 5 minutes can be arranged at different times.