Open main menu

Changes

2,321 bytes added ,  16:54, 24 January 2009
howto use cron on a server
Cron is the system scheduler on Unix/Linux/Mac operating systems. The ''crontab'' is the schedule of actions that the machine must keep. There are two types of crontabs in place on most systems: ''user crontabs'' and the ''system crontab''.

== Avoid User Crons ==
System administrators who manage servers and services should emphasize system crons over user crons. User crontabs are generally found under <code>/var/spool/cron/crontabs</code> and should be avoided in the context of managing cron for a server. They are intended for when a system is a multi-user system where individual users all may have regular maintenance scripts and commands that they manage themselves.

== System Cron Standard ==
example.com servers should all be using system crontabs to manage the functionality that the server is responsible for. Specifically, this includes the files <code>/etc/crontab</code>, the files under <code>/etc/cron.d/</code>, and usually, the <code>cron.hourly</code>, <code>cron.daily</code>, <code>cron.monthly</code> folders. All example.com-specific crontab entries should be made to the file <code>/etc/cron.d/example.com</code> or <code>/etc/cron.d/example.com-''something''</code>. If this file is not present, it should be created.

== How to edit crontabs ==
* Use a [[Text Editor]] to create/edit <code>/etc/cron.d/example.com</code> and add entries for new schedule jobs.
* Send notification to the [[Changes List]] about the adjustment.
* '''Comment''' Make sure your crontab entries include generous comments about what it does, when it does it etc, when it was implemented or last changed etc. Do not rely on the user's ability to read (cryptic) cron systax! nor force the user to inspect the contents of each script. Do point to reference sources like wiki or support URLs for detailed information. Complex scripts should be written independently, tested and saved to /root/bin where they can be easily called from cron.

==User crons==
Using ''user crontabs'' is discouraged for servers, but common in personal workstations or development environments

=== General crontab hints ===
* Use <code>crontab -l</code> to list the crontab for the current user
* Use <code>crontab -e</code> to edit the crontab for the current user
* <code>man crontab</code> can provide a lot more information.
4,558

edits