Cron/fr

Ce guide explique comme configurer et utiliser cron.

Que fait cron ?
Cron est un démon qui exécute des tâches programmées en se basant sur une table de commandes appelée. Il exécute ces tâches en s'éveillant toutes les minutes et en regardant s'il y a des tâches à lancer dans une crontab quelconque de l'utilisateur.

Le cron de facto
Il y a plusieurs mises en œuvre de cron dans Portage parmi lesquelles vous devez faire un choix. Elles ont toutes la même interface, nommément l'utilisation de la commande   ou d'une commande similaire. Il existe également un utilitaire appelé Anacron qui est prévu pour fonctionner avec cron sur des systèmes qui ne fonctionnent pas en permanence.

Ça vaut la peine de noter que tous les paquets cron disponibles dépendent de. Ce paquet n'est cependant techniquement nécessaire à aucun des paquets cron, mais il procure une fonctionnalité similaire à cron que la plupart des utilisateurs apprécient.

Avant de démarrer avec cron, vous devez choisir une mise en œuvre. Pour vous aider, nous avons rassemblé de l'information sur chacun d'eux ci-dessous.

Vixie cron
Vixie cron est une mise en œuvre de cron, basée sur SysV cron, comprenant toutes les fonctionnalités. Chaque utilisateur dispose de sa crontab et est autorisé à spécifier les variables d'environnement dans cette crontab. À la différence des autres variantes de cron, elle offre aussi la prise en charge de SELinux et PAM. Elle supporte moins d'architectures que Dcron, mais plus que Fcron.

Fonctionnalités de   :


 * Prise en charge de SELinux
 * Prise en charge de PAM
 * Définition de variables d'environnement dans les crontabs (PATH, SHELL, HOME, etc.)
 * Chaque utilisateur dispose de sa crontab; l'accès est contrôlé par et

Le Cron de Dillon
Dcron cherche à rester une mise en œuvre de cron, simple, élégante et sûre. Il n'autorise pas la spécification de variables d'environnement dans les crontabs et tous les cron-jobs sont lancés depuis. Comme Vixie cron, chaque utilisateur dispose de sa propre crontab.

Fonctionnalités de  :


 * Rapide, simple et débarassée de fonctionnalités inutiles
 * L'accès à la   est limité au groupe cron, i.e. il ne se fie pas à des facultés externes.

Fcron
Fcron cherche à remplacer Vixie cron et Anacron. Il est prévu pour fonctionner sur des systèmes qui ne sont pas toujours en marche et arrive avec des fonctionnalités supplémentaires. Il prévoit des contraintes de lancement des tâches, la sérialisation des contrôles, la possibilité d'ajouter des valeurs nice aux tâches et la possibilité de programmer les tâches à lancer au démarrage du système. Voir la page d'accueil de fcron pour plus d'information

Fonctionnalités de  :


 * Conçu pour fonctionner sur des systèmes qui ne tourne pas en permanence, i.e. il peut relancer une tâche au redémarrage de la machine si elle a été manquée.
 * Définition de variables d'environnement et de beaucoup d'autres fonctionnalités dans les  crontabs
 * Chaque utilisateur dispose de sa propre crontab, l'accès est contrôlé par cron.allow et  cron.deny
 * Syntaxe des crontabs améliorée avec prise en charge de nombreuses fonctionnalités nouvelles.

bcron
bcron est un nouveau système cron conçu pour des opérations sécurisées. Pour ce faire, le système est divisé en plusieurs programmes séparés, chacun responsable d'une tâche séparée, avec une communication strictement contrôlée entre eux. L'interface utilisateur est un remplaçant dérivé de systèmes similaires (tel que vixie-cron), mais les aspects internes différent profondément. Pour une plus ample information, reportez-vous à la page de bcron à http://untroubled.org/bcron/.

Features of  :


 * Drop-in replacement for vixie-cron
 * Multiprocess design
 * Native daylight savings time support

Anacron
Anacron is not a cron daemon, it is something that usually works in conjunction with one. It executes commands at intervals specified in days and it does not assume that the system is running continuously; it will run jobs that were missed while the system was down. Anacron usually relies on a cron daemon to run it each day.

Installation
Select the cron implementation you like the most, and then emerge it.

Optionally, if you have not installed Fcron, you may also want to install Anacron.

System crontab
The post install messages from some of these cron packages tell you to run. The file is your system crontab. A cron installation can use it in conjunction with  to run the scripts in. Note that only Vixie-cron schedules jobs in automatically. Dcron and Fcron users will need to run  every time they make changes to.

Please note that jobs scheduled in the system crontab might not show up in the list of cron-jobs displayed by.

Of course, you can choose not to use any system crontab at all. If you chose Dcron or Fcron, do not run. If you chose vixie-cron or bcron, you should comment all lines in.

Giving trusted users access to cron
If you want users other than root to have access to the cron daemon, you'll want to read this section, otherwise, you can proceed to the next section,.

No matter which cron package you use, if you want to allow a user to use crontab, he will first have to be in the cron group. As an example, if you wanted to add the user wepy to the cron group you would run:

If you're using Dcron, that's all you have to do to give a user access to crontab. Dcron users may proceed to the next section, all others will want to keep reading.

If you're using Fcron, you'll want to edit and. The most secure way is to first deny everyone in, and then explicitly allow users in.

Permissions in fcron.deny

Now, say we have a user wepy who should be able to schedule his own cron-jobs. We would add him to as follows:

Permissions in fcron.allow

If you chose Vixie cron, you'll probably just want to edit.

For example, if you wanted to allow access to the user wepy, you would add him to as follows:

Permissions in /etc/cron.allow

Scheduling cron-jobs
The process of editing crontabs is different for each package, but they all support the same basic set of commands: adding and replacing crontabs, editing crontabs, deleting crontabs, and listing cron-jobs in crontabs. The following list shows you how to run those commands for each package.

Before we can use any of these commands though, you first need to understand the crontab itself. Each line in a crontab needs to specify five time fields in the following order: the minutes (0-59), hours (0-23), days of the month (1-31), months (1-12), and days of the week (0-7, Monday is 1, Sunday is 0 and 7). The days of the weeks and months can be specified by three-letter abbreviations like mon, tue, jan, feb, etc. Each field can also specify a range of values (e.g. 1-5 or mon-fri), a comma separated list of values (e.g. 1,2,3 or mon,tue,wed) or a range of values with a step (e.g. 1-6/2 as 1,3,5).

That sounds a little confusing, but with a few examples, you will see that it is not as complicated as it sounds.

Examples

To test what we have just learned, let's go through the steps of actually inputting a few cron-jobs. First, create a file called and make it look like the this:

Now we can add that crontab to the system with the "new command" from the table above.

To verify the cron-jobs you scheduled, we'll use the proper list command from the table above.

You should see a list resembling, if not, maybe you used the wrong command to input your new crontab.

This crontab should echo "I really like cron" every minute of every hour of every day every other month. Obviously you would only do that if you really liked cron. The crontab will also echo "I like cron a little" at 16:30 every day in January and February. It will also echo "I don't really like cron" at 3:10 on the January 1st.

If you are using Anacron, you should keep reading this section. Otherwise, proceed to the next section on.

Anacron users will want to edit. This file has four fields: the number of days between each run, the delay in minutes after which it runs, the name of the job, and the command to run.

For example, to have it run  every 5 days, 10 minutes after Anacron is started, you would have:

/etc/anacrontab

Anacron exits after all of the jobs in anacrontab are done, so if we want it to check these jobs every day, we will need to use cron. The instructions at the end of the next section tell you how to do that.

Editing crontabs
Let's be realistic though, you don't want your system telling you how much you like cron every minute. As a step forward, let's remove that crontab using the corresponding remove command from the table above. We will also list the cron-jobs after, just to make sure it worked.

You should see no cron-jobs in the output from. If you do see jobs listed, that means we failed to remove the crontab, and that you should make sure that you used the correct remove command for your cron package.

Now that we have a clean slate, let's put something useful into the root crontab. Most people will want to run  on a weekly basis to make sure that   works properly. To add that to your crontab, let's first edit again so that it looks like the following:

A real crontab

That would make cron run updatedb at 2:22 A.M. on Monday morning every week. You should now input the crontab with the proper new command from the table above, and check the list again.

Now let's say that you also want to add  to your daily schedule. You could do this by first editing and then using   just as we did before, or you could use the proper edit command from the table above. This gives you a way to edit your user's crontab in situ, without depending on external files like.

That should open your user's crontab with an editor. We want to have  run every day at 6:30 A.M., so we'll make it look something like this:

A real crontab

Again, check the cron-jobs list as we did in the previous examples to make sure the jobs are scheduled. If they are all there, then you're all set.

Using cronbase
As mentioned earlier, all of the available cron packages depend on. The cronbase package creates, and a script called. You might have noticed that the default contains something like this:

Default system crontab

To avoid going into much detail, we can just assume that these commands will effectively run your hourly, daily, weekly and monthly scripts. This method of scheduling cron-jobs has some important advantages:


 * They will run even if your computer was off when they were scheduled to run
 * It is easy for package maintainers to place scripts in those well defined places
 * You know exactly where your cron-jobs and your crontab are stored, making it easy for you to backup and restore this part of your system

Final Notes
Remember, each cron package is different and the range of features varies greatly. Be sure to consult the man pages for crontab, fcrontab or anacrontab, depending on what you use.

Good luck!

Troubleshooting
If you're having problems getting cron to work properly, you might want to go through this quick checklist.

Is cron running?
Run  and make sure it shows up!

Is cron working?
Try the following:

crontab to see if cron is running

Then check if is modified periodically.

Is your command working?
Same as before, but perhaps redirect the standard error output as well:

crontab to verify application runs

Can cron run your job?
Check the cron log, usually or  for errors

Are there any s?
cron usually sends mail when there's a problem; check your mail and also look for.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Eric Brown
 * Xavier Neys
 * nightmorph