简体   繁体   中英

is crontab broken on OSX El Capitan?

Question. Is cron supposed to work in OSX El Capitan?

Background. I've used crontab for years on OSX, but with El Capitan it seems not to work. I added my username to /usr/lib/cron/cron.allow and even rebooted the machine, but still my cron jobs don't do anything, nor do they mail me with errors. The manpages suggest Apple doesn't want people using cron, but they don't say it is nonfunctional (yet).

It seems to work for me, but I think you need to specify the editor:

env EDITOR=nano crontab -e

Add your crons, and then save the file with the name and location given. In my case it's a file in /tmp/crontab.xxxx .

Then if you do crontab -l you should see your crons.

This is another answer for anyone that finds this via Google. There aren't many results.

For me, somehow /usr/lib/cron was symlinked to /var/at (which I'd never even heard of…), and /var/at had a cron.allow file, which my username wasn't in, so running sudo vi /var/at/cron.allow and adding my username (somehow redirecting echo into that file didn't work…) fixed it.

For Mojave, Full Disk Access prevents you from changing system files (which includes privacy related data as well as system configuration like the crontabs).

To enable access:

  • Go to System Preferences > Security & Privacy > Privacy > Full Disk Access
  • press the + button
  • Add your terminal app (eg /Applications/Utilities/Terminal.app or /Applications/iTerm.app)
  • Restart your terminal app
  • Configure cron
  • Optional, but highly recommended: Remove your terminal app from Full Disk Access when done

On a MacBook, using El Capitan (10.11.5), "cron" still works just fine.

"/usr/lib/cron.deny" is the default (lists "Guest" only), and there is no "cron.allow". Don't recall doing any customisations to make it work (no init/config files mods, no chmod's, no file/dir creates/deletes, etc.).

(Was using 10.6.* until that MacBook died in April. Began using 10.11 in mid-May, restored my crontab after the 10.11.5 update (?late May?). So don't know if cron was working under 10.11, or re-enabled by the 10.11.5 update.)

Try this simple test: "crontab -e", then "*/5 * * * * date >> /tmp/z.date". Should see a new date every five minutes.

If that works, try "*/5 * * * * env >> /tmp/z.date.1", and check your environment. Eg, the default PATH is quite short.

Btw, "at" is a batch job queue. "at", "batch", and "cron" are often grouped together, as they do variations of the same thing.

If you type cd /usr/lib/cron then ls you'll see you have at.deny and cron.deny , but no at.allow or cron.allow .

Run sudo nano cron.allow and enter your usernames one per line.

Create a copy for at.allow as such sudo cp cron.allow at.allow .

I created those two file and it started running.

cron will completely skip any jobs while the machine is asleep. Try checking your energy saver settings (see below).

launchd (Apple's recommended alternative) also doesn't run while the machine is asleep, but won't skip jobs. Instead the jobs run when the machine awakens.

节能器设置

According to Apple, cron was deprecated a while back. They must have finally pulled the plug in the GM of El Capitan. Apple suggests using launchd instead of cron. Here's a tutorial: launchd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM