The contents on this site are being moved to Highlander Nexus

ConfigureCrontab

From Linux and MacOSX Wiki
Jump to: navigation, search

Configuring Crontab

Purpose: This documentation will help configure crontab on your system to automate tasks.

Running a cron job consists of a schedule and command. The schedule being the minute, hour, day of the month, month, and day of the week the command should be executed.

  • For example, to run a command every minute:
  • Min |Hour |Day of the Month |Month |Day of Week
    * * * * *


  • To run a command everyday at 4:00am:
  • 0 4 * * *


  • To edit the crontab run:
  • crontab -e


  • To create a crontab that echos “Hello” every Friday at 3:30PM:
  • 30 15 * * 5 echo “Hello”


    Note: Cron uses 24-hour format starting from 0.

  • For example, to run a bash script located in the directory /home/rick/ the first of every month at midnight:
  • Min |Hour |Day of the Month |Month |Day of Week
    00 00 1 * * /home/rick/script.sh


    Names can also be used in cron.

  • For example, to run a backup of /home/rick/ every weekday at 10:30PM:
  • 30 22 * * Mon,Tue,Wed,Thu,Fri /usr/local/backup


    More shortcuts available in cron include @hourly, @daily, @weekly, @monthly, @yearly and @reboot.

  • For example, to have a job run on startup:
  • @reboot echo “System On”