Sunday, November 8, 2009

Cron job for linux.



For more information visit to the original site.
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Example(s)

If you wished to have a script named /root/backup.sh run every day at 3am, my crontab entry would look like as follows:

(a) Install your cronjob:
<code> # crontab -e
</code>(b)Append following entry:
<code>0 3 * * * /root/backup.sh
</code>Run five minutes after midnight, every day:<code>
5 0 * * * /path/to/command</code>
Run at 2:15pm on the first of every month:
<code>15 14 1 * * /path/to/command
</code>Run at 10 pm on weekdays:<code>
0 22 * * 1-5 /path/to/command </code>
Run 23 minutes after midnigbt, 2am, 4am ..., everyday:<code>
23 0-23/2 * * * /path/to/command
</code>Run at 5 after 4 every sunday:<code>
5 4 * * sun /path/to/command</code>

How do I disabling Email output?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1.<br /> For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1


To mail output to particluer email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1



No comments: