Apr 14

Cron on Debian 4.0 “Etch”

Category: Linux   — Published by tengo on April 14, 2008 at 3:57 pm

Every linux/unix based OS has a built-in scheduler, a tool to automate the execution of tasks/scripts/commands at a given time. This tool is the cron daemon.

cron directories

On debian 4.0 there are two procedures to add tasks to the cron table of events. The crontab and the cron directories:

If you navigate the directory structure, you will find a series of directories under the /etc branch labeled:

/etc/cron.hourly (scripts in this dir are executed hourly)

/etc/cron.daily (…executed daily)

/etc/cron.weekly (…executed weekly)

/etc/cron.monthly (…and executed monthly.)

If you need to have a script executed in one of these rhythms, just place it in the corresponding folder. Scripts placed here need to be chmodded to be executable: for example chmod 755 mybatch.sh.

I am unsure if a valid symlink (“ln -s <link> <target>“)  will do. At least you should make sure that the link target is executable (“chmod 0755“).


Actually, these dirs are just shortcuts. They real cron daemon, crond, is controlled via the crontab file- also residing in /etc. By default it contains the calls to process the dirs. If you need finer grained control about when a script is executed, you might as well edit crontab directly.

Try opening crontab in an editor. It will look like:


# run-parts
01 * * * * root nice -n 19 run-parts /etc/cron.hourly
02 4 * * * root nice -n 19 run-parts /etc/cron.daily
22 4 * * 0 root nice -n 19 run-parts /etc/cron.weekly
42 4 1 * * root nice -n 19 run-parts /etc/cron.monthly

Crontab editieren
There are special shortcut commands to edit the crontab:

Edit the crontab with “crontab -e” (which uses vi as editor).

To use another editor:


crontab -e

The format within crontab is
minutes – hours – days – months – dayofweek – command

for example:
0 1 * * * <command> # this is executed at 1 a.m.