At work, you often run into a script, or a command, every few days/hours/minutes. If it is every few hours, how many minutes to run the program, in the crontab may be a better implementation, the following are some examples and crontab format description:
Specific examples:
# 6 o'clock in the afternoon to the morning 6, every 15 minutes to execute a script
0,15,30,45 18-06 * * * */bin/bash $HOME/script.sh >/dev/null 2>&1
# Restart service every two hours
* */2 * * * */etc/init.d/apache2 restart
The following is a summary of how many minutes, every hour, daily/weekly/monthly/yearly crontab
0 0 1 1 *
If a script is executed every 10 days of the month, it can also be written as:
# 1th, 11th, 21st, 31st for each month, perform HTTP service restart
0 0 */10 * */etc/init.d/apache2 restart
But how do you do this if you're going to do it in natural days, say, every 27 days, a script? If this is the case, obviously can not be directly implemented through crontab, must be circuitous implementation. Here are two ways to think of it.
method One implements the control of time by scripting
Ideas:
1 set the number of times to execute in the script running.sh, if 10 times, each interval 27 days, script.sh for the script to be executed
2 then execute nohup bash running.sh & place it in the background for automatic execution
" method Two " is implemented indirectly through crontab
Ideas:
1 Execute the running.sh script regularly every day, and then judge in the script running.sh, when the time interval satisfies the condition
2 Execute the script.sh script while modifying the last execution time for the next execution