info home Info Homegeneral Generalwindows Windowsunix linux Linux/Unixdebian Debianmac os Mac OSapache Apachenginx Nginxiphone iPhone/iPod Touch

Tags

Cron task scheduling

Tags: cron

Cron is a Unix utility that allows processes/tasks to be run in the background at regular intervals or specific times.

To create or edit a cron, first set the EDITOR environment variable. I like emacs, so:

export EDITOR=/usr/local/bin/emacs

Commands

crontab -e         Edit crontab file
crontab -l         List crontab contents
crontab -r         Remove crontab contents

To disable email, add this to the end of the crontab entry:

>/dev/null 2>&1

Syntax of crontab line

MINUTE HOUR DAY-OF-MONTH (1-31) MONTH (1-12) DAY-OF-WEEK (0-6) COMMAND

Here are some cron jobs that I use regularly.

1. Run script /home/aruljohn/scripts/cleanup.sh on the 3rd of every month at 10:07 AM.

7 10 3 * * /home/aruljohn/scripts/cleanup.sh > /var/logs/cleanup.log 

2A. Run /home/aruljohn/scripts/monitor.sh every 20 minutes everyday (and log to file).

*/20 * * * * /home/aruljohn/scripts/monitor.sh > /var/logs/monitor.log

2B. Run /home/aruljohn/scripts/monitor.sh every 20 minutes everyday (with NO log).

*/20 * * * * /home/aruljohn/scripts/monitor.sh >/dev/null 2>&1

2C. Run /home/aruljohn/scripts/monitor.sh every 20 minutes everyday (and send email).

*/20 * * * * /home/aruljohn/scripts/monitor.sh

3. Run check.pl at 2am, 4am, 5am and 3pm

* 2,4,5,15 * * * /home/aruljohn/scripts/check.pl

Last Updated on 1 March 2010

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.