Linux-crontab and linux-crontab
I have learned a little about crontab before, And I am familiar with it some time ago. I will record it today.
Crontab commands are common in Unix and Unix-like operating systems and are used to set periodically executed commands. This command reads commands from the standard input device and stores them in the "crontab" file for later reading and execution.
When does crontab need to be used? The following are some good application scenarios:
- Run a program every minute to check the system running status.
- Statistics on the business data of the past day are required every early morning.
- Back up log files every week
- Back up the database every month
Install crontab
The installation in ubuntu is as follows:
sudo apt-get install cron
Time settings
# File format description # -- minute (0-59) # | -- hour (0-23) # | -- Day (1-31) # | -- month (1-12) # | -- week (0-7) (Sunday = 0 or 7) # | # *** executed command
Note:
Indicates the command to be executed from the sixth domain.
Crontab command
crontab [ -u user ] [ -i ] { -e | -l | -r } (default operation is replace, per 1003.2) -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab) -i (prompt before deleting user's crontab)
Crontab example
Restart nginx at every night
30 21 *** service nginx restart
Restart nginx at on May 1, 10, and 22 every month
45 4, 22 ** service nginx restart
Restart nginx at from the first day of every month
45 4 1-10 ** service nginx restart
Restart the nginx server every 2 minutes
*/2 ***** service nginx restart
1-59/2 *** service nginx restart
Restart nginx every hour between PM and PM.
0 23-7/1 *** service nginx restart
Restart nginx every 30 minutes from to every day
0, 30 18-23 *** service nginx restart
0-59/30 18-23 *** service nginx restart
Summary
- * Indicates matching at any time
- You can use "A, B, C" to execute commands When A, B, or C is used.
- You can run the command to represent A to B with "A-B"
- You can use "*/A" to execute A command every hour.