How to add a job to crontab and set simple email address?


Using cron you can execute a shell-script or Linux commands at a specific time and date. For example a sysadmin can schedule a backup job that can run every day.

How to add a job to the cron?

# crontab -e

MAILTO=abc@abc.com

0 4 * * * /root/bin/abc.php

 

This crom will be executed everyday @ 4AM and out will be emailed to abc@abc.com

Description of Cron fields.

Following is the format of the crontab file.

{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script}
  • minute: Allowed range 0 – 59
  • hour: Allowed range 0 – 23
  • day-of-month: Allowed range 0 – 31
  • month: Allowed range 1 – 12. 1 = January. 12 = December.
  • Day-of-week: Allowed range 0 – 7. Sunday is either 0 or 7.
 

Crontab examples

1. Run at 12:01 a.m. 1 minute after midnight everyday.

This is a good time to run backup when the system is not under load.
1 0 * * * /root/bin/backup.sh

2. Run backup every weekday (Mon – Fri) at 11:59 p.m.

59 11 * * 1,2,3,4,5 /root/bin/backup.sh
Following will also do the same.
59 11 * * 1-5 /root/bin/backup.sh

3. Execute the command every 5 minutes.

*/5 * * * * /root/bin/check-status.sh

4. Execute at 1:10 p.m on 1st of every month

10 13 1 * * /root/bin/full-backup.sh

5. Execute 11 p.m on weekdays.

0 23 * * 1-5 /root/bin/incremental-backup.sh

Crontab Options

Following are the available options with crontab:
  • crontab –e : Edit the crontab file. This will create a crontab, if it doesn’t exist
  • crontab –l : Display the crontab file.
  • crontab -r : Remove the crontab file.
  • crontab -ir : This will prompt user before deleting a crontab.

 

No comments

Enter your email address:

Delivered by FeedBurner

OR

 Subscribe in a reader

 
Latest Blogs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Tips for optimizing php code by PHP Expert Important SERVER Variables in PHP - By PHP Expert Improved Error Messages in PHP 5 - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert Object Overloading in PHP 5 Persistable Classes - By PHP Expert Dynamic Getter/Setter Methods - By PHP Expert New Functions in PHP 5 New Directives - By PHP Expert Exception Handling - By PHP Expert Password Encryption in PHP - By PHP Expert Output Buffering in PHP - By PHP Expert Page Excerpts Using CURL - By PHP Expert Quick and Easy Google Site Search - By PHP Expert Always Be Notified When Google Crawls Your Site - By PHP Expert How to POST Form Data using CURL - By PHP Expert Cryptography for web developers - By PHP Expert Dynamically Loading JavaScript Files - by PHP Expert What is Web 2.0 - By PHP Expert