linux built-in cron process can help us achieve these requirements, with a cron shell script, very complex instructions no problem.
Introduction cron
We often use the crontab command cron table shorthand, it's cron configuration file, you can also call it job list, we can find the configuration file in the following folder files.
- / Var / spool / stored under cron / directory of each user, including root's crontab task, the name of each person's name to create a task
- / Etc / crontab file is responsible for scheduling the various management and maintenance tasks.
- /etc/cron.d/ This directory is used to store any crontab files or scripts to be executed.
- We can also put the script on /etc/cron.hourly,/etc/cron.daily,/etc/cron.weekly,/etc/cron.monthly directory, make per hour / day / week, once a month to perform.
use crontab
the crontab [-u username] // omit the user's current user operation table showing the crontab - E (Table editing) - L (listed in the table work order) -R & lt (deleted for work)
We use crontab -e to enter the user's current worksheet editor, vim is a common interface. Each line is one command. Save and exit, take effect, the default crontab will be checked every minute task files.
crontab command configured + action time, which time has minute, hour, day, month, week five, at operator has
- * All numbers in the range of
- / How many numbers every
- - from X to Z
- , Hash digital
Journal
Plan tasks performed, log in / var / log / cron can view the execution logs for analysis see
pay attention
crond tasks planned, and does not call the environment variables set by the user, it has its own environment variables, when you use some commands, such as mysqldump commands required environment variables, when performed manually script is normal, but with crond when the execution will not, then you either write the full absolute path, or adding an environment variable to / etc / crontab in. In addition, ceontab inconvenient to execute statements variety of tasks, often recommended or shell script is written in python script execution.
Examples
Example 1: myCommand performed once per minute
* * * * * myCommand
Example 2: 3 and every hour in the first 15 minutes of
3,15 * * * * myCommand
Example 3: 3 and performed in the first 15 minutes of 8:00 to 11:00
3,15 8-11 * * * myCommand
Example 4: 3 and performs the first 15 minutes of every day 8:00 to 11:00
3,15 8-11 */2 * * myCommand
Example 5: 3 and 8:00 of 15 minutes to 11 performed weekly
3,15 8-11 * * 1 myCommand
Example 6: night 21:30 smb restart
30 21 * * * /etc/init.d/smb restart
Example 7: 1 month, 10, 22, the 4:45 restart smb
45 4 1,10,22 * * /etc/init.d/smb restart
Example 8: every Saturday and Sunday 1:10 to restart the smb
10 1 * * 6,0 /etc/init.d/smb restart
Example 9:18 per day: smb restart every 30 minutes 00: 00-23
0,30 18-23 * * * /etc/init.d/smb restart
Example 10: Every Saturday night, 11: 00 pm restart smb
0 23 * * 6 /etc/init.d/smb restart
Example 11: smb restart every hour
* */1 * * * /etc/init.d/smb restart
Example 12: between 11 pm to 7 am, every hour restart smb
* 23-7/1 * * * /etc/init.d/smb restart
Example 13: daily 0:00 execution curator
0 0 */1 * * curator --config /opt/elasticsearch-curator/config.yml /opt/elasticsearch-curator/action_all.yml