Difference between revisions of "Setting Up a Cron Job"

From rbachwiki
Jump to navigation Jump to search
Line 25: Line 25:
|}
|}


{|
{| class="wikitable" style="margin:auto"
|Every Minute
|Every Minute
|* * * * *
|* * * * *

Revision as of 15:08, 17 May 2024

Setting Cron to run on Mac Os

  • Cron needs full disk access in order to run on mac
  • Go to System Settings > Privacy & Security > Full Disk Access:
  • Click on the (+) icon to add an item to the list.
  • Press command+shift+G, type /usr/sbin/cron and press enter:
  • Select the cron executable and click Open

Setting up a Cron Job

crontab -e  # use the -e switch, do not edit the file directly 
crontab -l # shows scheduled jobs
crontab -r  # remove the current crontab file

Crontab sections

Parts of cron tab
Minute Hour Day (month) Month Day (week)
* * * * *
0-59 0-23 1-31 1-12 or jan, feb,mar,.. 0-6 or sun, mon, tue
Every Minute * * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *
Ever 5 Minute */5 * * * *


  • minute of the hour the command will run on, and is between '0' and '59'
  • hour the command will run on, and is specified in the 24 hour clock, values must be between 0 and 23 (0 is midnight)
  • Day of Month, that you want the command run on, e.g. to run a command on the 19th of each month, the dom would be 19.
  • month a specified command will run on, it may be specified numerically (0-12), or as the name of the month (e.g. May)
  • the Day of Week that you want a command to be run on, it can also be numeric (0-7) or as the name of the day (e.g. sun).
  • user who runs the command.
  • command that you want run. This field may contain multiple words or spaces.
* 12 10-16/2 * * root backup.sh

When using the names of weekdays or months, it isn't case sensitive, but only the first three letters should be used, e.g. Mon, sun or Mar, jul.

Comments are allowed in crontabs, but they must be preceded with a '#', and must be on a line by them self.


Back To Top- Home - Category