LinuxMoz

Linux Stuff && Coffee

Crontab Every 5 Minutes

| Comments

How to run crontab every 5 minutes detailed instructions and a Linux crontab example showing you how to run a cron job every 5 minutes.

Below is an overview of how the crontab file format, for a more detailed explanation visit our crontab syntax page.

1
2
3
4
5
6
7
  #---------------- Minute (0 - 59)
  |  #------------- Hour (0 - 23)
  |  |  #---------- Day of the Month (1 - 31)
  |  |  |  #------- Month (1 - 12)
  |  |  |  |  #---- Day of the Week (0 - 6) (Sunday=0 or 7)
  |  |  |  |  |
  *  *  *  *  *  example-script.sh

Edit your crontab with:

1
crontab -e

To run crontab every 5 minutes add the following to your crontab file:

1
*/5 * * * * /path/example-script.sh

The same applies if you want to run the script directly from the crontab, see the example below:

1
*/5 * * * * grep "darth vader" /var/log/maillog | mail root

The above would run crontab every 5 minutes and search the mail log for darth vader and email me the output (note this would send the email regardless if it found darth vader or not).

Comments