Difference between revisions of "Setting Up a Cron Job"

From rbachwiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 5: Line 5:
* Press command+shift+G, type /usr/sbin/cron and press enter:
* Press command+shift+G, type /usr/sbin/cron and press enter:
* Select the cron executable and click Open
* Select the cron executable and click Open
==Vim Editor Commands==
shift + :
* :i // insert text
* :wq Write file to disk and quit the editor


== Setting up a Cron Job ==
== Setting up a Cron Job ==
Line 22: Line 27:
|-
|-
|0-59||0-23||1-31 ||1-12 or jan, feb,mar,..||0-6 or sun, mon, tue
|0-59||0-23||1-31 ||1-12 or jan, feb,mar,..||0-6 or sun, mon, tue
|}
{| class="wikitable" style="margin:auto"
|Every Minute||* * * * *||Ever 5 Minute||*/5 * * * *||Ever 30 Minutes||*/30 * * * *
|-
|Every Hour||0 * * * *||Every Hour and 30 min||30 * * * *||Ever 2 hours||0 */2 * * *


|}
|}
Line 34: Line 46:
* command that you want run. This field may contain multiple words or spaces.
* command that you want run. This field may contain multiple words or spaces.


 
  * 12 10-16/2 * * /scripts/backup.sh
  * 12 10-16/2 * * root backup.sh


<p class="subhead">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.</p>
<p class="subhead">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.</p>

Latest revision as of 16:57, 31 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

Vim Editor Commands

shift + :
  • :i // insert text
  • :wq Write file to disk and quit the editor

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 30 Minutes */30 * * * *
Every Hour 0 * * * * Every Hour and 30 min 30 * * * * Ever 2 hours 0 */2 * * *


  • 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 * * /scripts/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