MacOS provides Crontab utility tool, Crontab enables the user to execute commands or scripts periodically at predetermined times.

Below are some basic commands that will enable you to use Crontab utility in Mac.

Binary location:
/usr/sbin/cron

You need to provide Full Disk Access to cron application to make the Crontab work.

Full Disk Access to crontab:
  • Goto System Preferences >> Settings & Privacy
  • Select the Privacy tab
  • Find and select Full Disk Access option
  • From the right – click “+” to add the crontab
  • When File Explorer window is opened use <Command>+<Shift>+G this will open a new window with go to folder option.
  • Paste the above path and click “go
  • This will add crontab application to have the Full Disk Access

Using Crontab:

Listing exiting crontab jobs:

crontab command with “-l” will list the existing Crontab jobs available in the system.

crontab -l
Editing crontab:

crontab command with “-e” will open the crontab file in editing mode.

crontab -e

example:
Adding below line in the file will runs ls command on the target directory everyday at 7:00 am

* 7 * * * /bin/ls <dir> # cron format *<minute>(0-59)  *<hour>(0-23)  *<date>(1-31)  *<month>(1-12)  *<day>(0-6)
Removing crontab:

crontab command with option “-r” option will delete the crontab.

crontab -r

Leave a Reply

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

Verified by MonsterInsights