Some liunx systems already have their own scheduled tasks crontab, but some of the newly installed systems have not yet set up scheduled tasks, and this time we need to install them manually.
Install Crontab:
Yum Install Crontabs
Description
/sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration
View crontab Service Status: Crond status
Manually Start crontab services: Service Crond start
To see if the Crontab service is set to boot, execute command: NTSYSV
Add to boot auto start:
Chkconfig–level Crond on
1,crontab command
Feature Description: Set the timer.
Syntax: crontab [-u < user name >][profile] or crontab [-u < user name >][-ELR]
Additional note: Cron is a resident service that provides the function of a timer that allows the user to execute a preset instruction or program at a specific time. The function of the timer can be used as long as the user edits the timer's configuration file. Its configuration file format is as follows:
Minute Hour Day Month DayOFWeek Command
Parameters
-e Edit the user's timer settings.
-l lists the user's timer settings.
-R removes the user's timer settings.
-u< User name > Specifies the user name to set the timer.
2,crontab format
Basic format:
* * * * * command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run
# Use the hash sign to prefix a comment
# + —————-minute (0–59)
# | + ————-Hour (0–23)
# | | + ———-Day of month (1–31)
# | | | + ——-Month (1–12)
# | | | | +--Day of Week (0–7) (sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
Some examples of crontab files:
* * * * */etc/init.d/nginx restart
21:30 restart Nginx per night.
4 1,10,22 * */etc/init.d/nginx restart
1, 10, 22nd of the 4:45 restart Nginx.
1 * * 6,0/etc/init.d/nginx restart
Every Saturday, Sunday, 1:10 restart Nginx.
0,30 18-23 * * */etc/init.d/nginx restart
The nginx is restarted every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/etc/init.d/nginx restart
Restart Nginx every Saturday at 11:00am.
* */1 * * * */etc/init.d/nginx restart
Restart Nginx every hour
* 23-7/1 * * * */etc/init.d/nginx restart
From 11 o'clock to 7 in the morning, restart nginx every hour.
0 4 * Mon-wed/etc/init.d/nginx restart
4th number per month and 11-point restart from Monday to Wednesday
0 4 1 Jan */etc/init.d/nginx restart
4-point restart of nginx on January 1
*/30 * * * */usr/sbin/ntpdate 210.72.145.20
Synchronize time every half hour
Scheduled tasks for the CentOS server configuration (iii)