C r O n cron cron reads one or more configuration files containing scheduled tasks. c r o n t a b " " crontab" “Crontab.
Cron service
service crond start # start service
service crond stop # service shutdown
service crond restart # restart service
service crond reload Reload the configuration
service crond status Check service status
Copy the code
The configuration file
/var/spool/cron/ # All user cron tasks
/etc/crontab/ # CrON tasks set by the system administrator
/etc/cron.d/ # Cron script file to execute
Copy the code
Add the homework
crontab -e
Copy the code
Crontab The crontab file is automatically created if it does not exist. If you use it for the first time, you are prompted to select the editor and add information about scheduled tasks at the end of the command. Exit and save the configuration. For example:
15 10 * * * your/script/path
Copy the code
/your/scr I pt/path /your/script/path /your/script/path
Homework format
C ron cron Scheduled task Information about cron jobs has a fixed format:
{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script}
Copy the code
M I nute minute Minute The value ranges from 0 to 59 0 \sim 59 0 to 59, h O u R hour hour The value ranges from 0 to 23 0 \sim 23 0 to 23, D ay− O f−mont H day-of-month day−of−month Values range from 1 to 31 1 \ SIM 31 1 to 31, M onth month Month Value range: 1 to 12 1 \sim 12 1 to 12, D ay−of−wee K day-of-week day−of−week Ranges from 0 to 7 0\ sim 7 0 to 7. Sunday can be 0 or 7 0\ or 7 0 or 7, F u L L − P a T H − T O − S H E L L − S C r I pt Full-path-to-shell-script Full −path−to−shell−script Indicates the script to be executed.
Check the homework
crontab -l
Copy the code
The cr O N T ab crontab crontab file is displayed. You can view the job information of all scheduled tasks.
Delete operation
crontab -r
Copy the code
You can delete the cro N T ab crontab crontab file. After the crontab file is deleted, all scheduled tasks are deleted. If you want to delete certain scheduled tasks, You can select − E-E − E to edit c R O N T ab crontab To delete tasks from the crontab file.
crontab -lr
Copy the code
Delete the cro N T ab crontab crontab file and remind the user.
The sample
Execution per minute
* * * * * script
Copy the code
Every hour 15, 15, 15 minutes and 45, 45, 45 minutes
15, 45 * * * * script
Copy the code
Every day from 8 to 11 8 \ SIM 11, 15, 15 and 45, 45 minutes
15, 45 8-11 * * * script
Copy the code
Every other day at 8:15 a.m. 8:15 a.m. 8:15 a.m
15 8 */2 * * script
Copy the code
Every Monday morning at 10:15 10:15 10:15
15 10 * * 1 script
Copy the code
It is executed at 10:15 10:15 on the 11th day of each month
15 10 1 * * script
Copy the code