Configuring a cron job using crontab -e

  1. Knowledge Base
  2. Operating System
  3. Systems Administration
  4. Linux
  5. Configuring a cron job using crontab -e

A cron job is a script that is scheduled to run at on a recurring basis according to the specified Day of Week, Month, Day of Month, Hour and Minute parameters. The crontab is a configuration file that is used to schedule the cron jobs. To edit the crontab run the following command:

crontab -e

Example crontab file that will run the script.sh file every morning at 7AM:

SHELL=/bin/bash
HOME=/root
PATH=/bin
LANG=en_US.UTF-8
PWD=/root
MAILTO="[YourEmail@YourDomain]"
#*     *     *     *     *  Command to be executed
#-     -     -     -     -
#|     |     |     |     |
#|     |     |     |     +----- Day of week (0-7)
#|     |     |     +------- Month (1 - 12)
#|     |     +--------- Day of month (1 - 31)
#|     +----------- Hour (0 - 23)
#+------------- Min (0 - 59
# Entries:
0 7 * * *  /Path/to/your/scripts/script.sh

You may enter as script calls as you would like after the #Entries: line. After editing the crontab be sure to save your changes by pressing shift + colon then type wq and press enter.

Note: You may name your script files anything you would like, but be sure that your script files are marked as executable using chmod.

Additionally, you may occasionally have to restart the crond daemon.

Further details of CRON commands may be found on the following pages:
How To Use Cron To Automate Tasks On a VPS
Linux Start Restart and Stop The Cron or Crond Service

Leave a Reply

Your email address will not be published. Required fields are marked *