Rob's web

Cron

Cron is a time-based job scheduler, it is configured it to run commands at given times or intervals. Each User has a cron table which defines what to execute and at what interval. crontab command is used to create, modify and view cron jobs.

Configuration files and directories

DirectoryTime
/etc/cron.hourlyFirst minute of every hour
/etc/cron.dailyBetween 3:05 AM to 10.55 PM each day
/etc/cron.weeklyBetween 3:25 AM and 11:10 PM after 7 days since last execution
/etc/cron.monthlyBetween 3:45 AM and 11:30 PM after a month since last execution

All the sysadmin needs to do is to place a shell script or a link to an executable in one of the directories and it will automatically be run at the appropriate time.

Crontab

With crontab you can run an script at every time you need without be dependend on the regular routines.

For an example file enter:

# cat /etc/crontab
SHELL=/usr/bin/bash
PATH=/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

Lets create an job that runs every 5 minutes. This opens the vi editor.

# crontab -u apache -e
*/5 * * * * sudo -u apache php /srv/www/vhosts/cloud.robkalmeijer.nl/httpsdocs/cron.php

Links