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 Answers
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.
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.
cron
has been deprecated in favor oflaunchd
. Have a look at this answer for a primer on how to setup alaunchd
job that executes at a given interval.launchd
makes the job easier but likecron
because I just have to type one line. I am lazy :)