Configuration and Concepts
See this when looking for crontab, both look alike but after understanding the function, discover Annacron is not a cyclic execution of the command, only a scheduled task, and support the minimum granularity is the day. To do the loop we can think of using crontab to combine with it.
Anacron has a self-contained profile, and if you are centos,red hat some of the most common Linux, the system will be installed with this feature. Configuration file in/etc/anacrontab interested partners can open to see (lazy words with me to see it ~).
As you can see, there are a few lines at the end of the configuration file with a description of the task in a similar format to crontab. The above comment also gives what each field represents. A reading: The first column period in the days: the time interval. The following 1, 7, on behalf of the interval of 1 days, 7 days to perform a second column delay in minutes: The time interval after the start of the task (the actual interval is to be said together with another control parameter) the third column job Indentifier: It's a loud name for your mission. Here's the cron.daily,cron.weekly ... That's it. Fourth command: Specific commands here: Nice run-part/etc/cron.daily ... Many of the small partners here may not understand this command, will only shout nice. Nice in Linux is a command that lowers the Cheng of the optimal line. Here is a simple point, know is to lower the priority on it. Go over it after class.
One of the questions left is that another control parameter for delay time.
In the screenshot we can see random_delay this parameter, then the clever small partner can think of, the actual time delay= the second column value +random_delay (in the unit is minute)
Also see a configuration parameter is: start-hours-range=3-22
This represents the time interval of the task's allowable execution, and how to understand it. Give me a chestnut.
Assuming it's 1 o'clock in the afternoon, I set up a Anacron task, and then about a few minutes later, the task will be executed. However, the task has 3-22 this limit, then wait until 3 o'clock before it can be executed, so the real execution time is: 3+delay. Operation
Let's say how to write a Anacron command of your own
First, you have a configuration file. System/etc/anacrontab This file is not to touch it, we write a new configuration file. Create a new file under a folder you like, assuming that it's called Anacrontest .
Vim anacrontest The
configuration file of the system to copy down and write some of your own commands. is to delete its nice xxxx command and write a command.
final execution:
anacron-t Your profile -s/var/anacrontest explain the
parameters:-T after specifying the configuration file, because this is a new configuration file, we need to tell it the location of the configuration file - S (uppercase) indicates that a folder that already exists is selected to hold the timestamp of the last task performed. The
default timestamp store location is under the/var/spool/anacron folder, you can open this folder, there should be cron.daily and so on three files. Corresponds to the three task names for the system task. Inside Open Look:
is a time stamp. The time when the last task was executed was recorded. (Picture is cron.daily) supplement
Before seeing on the net has said crontab when shuts down the computer if missed the next time which runs the task, then crontab task will be ineffective. I did an experiment here myself. Set up a task using crontab, create a new file every two minutes, and two minutes later the task takes effect and the file is generated. Shut down the machine. Interval of about five minutes, according to the web, at this time the crontab task is invalidated, because the next time the file is generated is shutdown state. I boot again, two minutes later, the file continues to generate, stating that the statement is not correct, you can determine the shutdown, even missed the crontab task execution time, the task will not fail.