You are Here: FAQ ->Dedicated Servers->Linux Root Server->How To?->Article #1


WebHosting 5.0 This article is for 1&1 Linux WebHosting only.


How to setup a cron job


Cron jobs can help you to automate certain procedures e.g. backup. This article is
a brief "how-to" for creating a cron field which defines when a specific
application or script should be executed.

Execute the command "crontab -e" to generate or edit your cron-file. Alternatively
use "crontab -l" for listing your cron jobs or "crontab -r" for deleting all cron
jobs.

One line in the cron file looks like this:
1 2 3 4 5 /etc/myScript arguments

The five numbers at the beginning of the line represent the following:
1: minutes (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 or January, February, ... 0 and 12=December)
5: Day of the week(0-7 or Monday, Tuesday, Wednesday, ... 0 and 7=Sunday)
This enables you to exactly define when a script is supposed to be started.

Wait, there is more! You can make the file even more flexible like this:
*: applies every time
1-4: start if 1,2,3 or 4 matches
1-4/2 step-by-step, here: 1 and 3
1,5,6: enumeration
*/3: every third
1-4,10-15: enumeration and range combined

Moreover you can define what SHELL is to execute the commands and who you want to
send the results to (via e-mail):
SHELL=/bin/bash
MAILTO=me@localhost

A few more examples:
# every day at 0:05
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1

# every first day of the month at 14:15
15 14 1 * * $HOME/bin/monthly

# on weekdays at 22:00
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%

# every day 23 minutes after every even hour (0:23, 2:23, ...)
23 0-23/2 * * * $HOME/status.sh

# Sundays at 4:05
5 4 * * sun $HOME/backup.sh full

Weekdays and calender days do not exclude each other but are considered
separately. If either pattern matches the script will execute.


SD2B2C810


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not useful at all):
1 2 3 4 5