10

I've set up cron to run a script hourly but when I reboot cron does not work. Does this mean that I should run cron whenever I boot into my Mac? The cron command which I use cron 5 * * * * path/to/script.sh. Is there any problem with cron or I this kind of behaviour expected?

2
  • cron has been deprecated in favor of launchd. Have a look at this answer for a primer on how to setup a launchd job that executes at a given interval.
    – Allan
    Commented Oct 30, 2017 at 14:39
  • @Allan I know that launchd makes the job easier but like cron because I just have to type one line. I am lazy :)
    – user244378
    Commented Oct 30, 2017 at 15:12

2 Answers 2

8

You don't need to call cron directly. Any commands you want to run need to be added to the crontab of the user they should run as. You can edit your crontab by running

crontab -e

or, if you are an admin user and want to edit the crontab of another user,

crontab -u USERNAME -e

PS: Run man 5 crontab for details about the format of the file, what kind of special commands you can use, and some samples. 5 * * * * /path/to/script seems to be ok though.

5

On macOS High Sierra (and perhaps earlier), cron is disabled in some configurations. There is, however, still a LaunchDaemon for it.

Check to see if cron is enabled:

sudo launchctl list | grep cron

You should see com.vix.cron.plist if cron is running. If cron is not running, you should do:

sudo launchctl load -w /System/Library/LaunchDaemons/com.vix.cron.plist

That will start cron, and the -w switch will make sure it starts after reboots as well.

You must log in to answer this question.