Prior to understand a little crontab, the previous period of time more idle, familiar with a bit, today summary record.
The crontab command is commonly used in Unix-and Unix-like operating systems to set instructions that are executed periodically. The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution.
When do I need to use crontab? Here are a few good scenarios.
- A program needs to be executed every minute to check the system running status
- Need to count business data for the past day in the wee hours of the day
- Log files need to be backed up every week
- Need to back up the database every month
Installing crontab
The installation in Ubuntu system is as follows:
sudo Install cron
Time setting
# File Format Description # --minutes (0| --Hours (0| | --Day (1| | | --month (1| | | | --Week (07) (Sunday= | | | | | * * * * * Command executed
Note:
- In the "Day of the Week" (fifth field), 0 and 7 are considered Sunday.
- Not very intuitive to use: if the date and week are set simultaneously, then one of the conditions is satisfied, the instruction will be executed.
- The first 5 fields are called the time of day and week , can be convenient for personal memory.
From the sixth field, indicate the command to execute.
crontab command
crontab [-u user] [-i] {-e |-L |-r }1003.2) -E (edit users CR Ontab)- l (list user's crontab) -R (delete user's crontab) -I (Prompt before deleting user's crontab)
crontab Example
Restart Nginx every 21:30
* * * Service Nginx restart
1, 10, 22nd of 4:45 restart Nginx
4 1,10,22 * * Service Nginx restart
1-10 days a month 4:45 restart Nginx
4 1-10 * * Service Nginx restart
Restart the Nginx server every 2 minutes
*/2 * * * * Service Nginx restart
1-59/2 * * * * Service Nginx restart
From 11 o'clock to 7 in the morning, restart nginx every hour.
0 23-7/1 * * * Service Nginx restart
Restart Nginx every 30 minutes from 18:00 to 23:00 every day
0,30 18-23 * * * Service Nginx restart
0-59/30 18-23 * * * Service Nginx restart
Summary
- * Indicates any time to match
- You can use "A,b,c" to represent A or B or C when executing A command
- You can use "A-B" to represent the command
- You can use "*/a" to indicate that every A-minute (hour, etc.) command is executed
Learning--crontab for Linux