Aug
9
2012

Linux Cron Configuration

Cron is a scheduled task mechanism for unix/linux environment.

Cron main configuration file is /etc/crontab. Additionally cron has folders which will run hourly (/etc/cron.hourly), daily (/etc/cron.daily) and monthly (/etc/cron.monthly).

Cron commands :

crontab -e >> edits crontab file with vi editor.
crontab -l >> lists cron entries.

Creating scheduled jobs :

To create a scheduled script you should edit /etc/crontab file :

Crontab file structure :

* means every.

*/5 9 31 * *  /home/user/test.pl

#  .—————- Second (0 – 59)
#  |     .————- Hour (0 – 23)
#  |     |     .———- Date of Month (1 – 31)
#  |     |     |    .——- Month (1 – 12) or jan,feb,mar,apr …
#  |     |     |    |   .—– Date of Week (0 – 6) (Sunday=0 or 7) veya sun,mon,tue,wed,thu,fri,sat
#  |     |     |    |   |
#  *     *     *    *   *

Examples :

Script will run every 30 seconds :

*/30  *  *  *  *     /scriptPath

Everyday 14:00 and 21:00

00 14,21 * * * /scriptPath

Everyday and every-hour between 09:00 and 18:00

00 09-18 * * * /scriptPath

Every weekday(Monday to Friday) between 09:00 and 18:00

00 09-18 * * 1-5 /scriptPath

About the Author: Bülent Özkan

Leave a comment

You must be logged in to post a comment.