![]()
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
What is it used for?Cron is a system used on Unix systems to execute commands at determined times. The main interest of this concerns administrative tasks: a server administrator would use cron to start every night a backup of his servers. How does it work?cron works thanks to the crond daemon. This program is started on a machine once for good and for every user. Users can parameter their own cron system with a small tool called crontab. The only problem is that crontab is the only standard program available to parameter crond and it is based on vi... Crontab will give instructions to crond: when to execute a program and the rights with which it should be executed. Obviously, standard users cannot ask crond to start a program with the rights of another user, especially the super user (root); it would be too dangerous. How to use crontabTo use it, it is essential to know how to use vi. The first thing to do is to log on the machine as the user that should execute the commands. However, it is possible
for the super user (root) to set another user for crond without explicitely log on the server as it by using the
To start crontab and configure crond, we simply type: Configuration of crondcrontab lines are of 2 kinds: there are cron commands, i.e. the system commands that crond should execute at a determined time, and environment variable definitions. Comments are possible using a #. cron commandsThey are provided line by line. They have the following format:
Commands are simply those the user would type if he had to execute them by himself. A time can be divided into 5 fileds:
Fields are separated by spaces and if several elements of the same group must be provided, they are separated by commas (without space). A star (*) means: "for every element of this category". Example: 0,10,20,30,40,50 * 1 * 7 /usr/bin/foo
This line means: "execute /usr/bin/foo every 0, 10, 20... minutes of every hour of the first day of every month if this day is a monday, and this every year..." The combination may seem to be weird but it is extremely powerful. Basically, the principle is to parameter only relevant elements and to put a * everywhere else. To start foo every single minute, just use: * * * * * /usr/bin/foo
The most frequently you can ask crond to execute a command is every minute. Environment variablesCrontab lines can also be used to (re)set environment variable for executing cron commands. It is very easy to do: VARIABLE=VALUE
This line will set VALUE to the the variable VARIABLE. It is possible to ask crond to reset environment variables set in .profile or .bashrc, except the LOGNAME variable for obvious security reasons. There is only one imperative: when setting a variable, never use spaces unless it is a string. ReferencesLes manual pages:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Copyright © 2000-2002 themanualpage.org - This site is submissive to the terms of the GNU GPL and FDL licences. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||