39

Until now, I have never attempted adding a crontask on my Mac. To my surprise, it threw an error..

[hayek@mac:/www/] 02:33:22 PM: crontab -e                                                                                                         1 .
crontab: no crontab for hayek - using an empty one
crontab: "/usr/bin/vi" exited with status 1

How can I figure out why it's throwing that error?

I'm running Mac OS X Lion 10.7.2

Hayek
  • 2,085

9 Answers9

44

The issue turned out to be vi and nothing to do with cron. Doing export EDITOR=vim fixed it

Journeyman Geek
  • 133,878
Hayek
  • 2,085
43

In ~/.vimrc add:

    autocmd filetype crontab setlocal nobackup nowritebackup
34

On a related issue, if you get the message:

crontab: temp file must be edited in place

Try:

1) Add to .bash_profile

alias crontab="VIM_CRONTAB=true crontab"

2) Add to .vimrc

if $VIM_CRONTAB == "true"
    set nobackup
    set nowritebackup
endif

Source: http://drawohara.com/post/6344279/crontab-temp-file-must-be-edited-in-place

xgMz
  • 551
8

Your editor on system variable EDITOR is vi and vi itsn't work.

Try:

export EDITOR=nano
2

I had the same problem and followed the advice posted for creating the table:

crontab file

And that created the cron table, and then I was able to run

crontab -e

with vi as the default editor and had no problems. It is as if vi could not save the file, but once created, it could access it. This is consistent with being able to run:

sudo crontab -e 

As a curiosity, the tables are stored in

/usr/lib/cron/tabs/UserName

which can only be read as sudo.

0

The best way to diagnose this would be to create a fresh crontab with a simple entry like:

* * * * * /bin/date >> /tmp/cron_output

If that works then the issue is with the specific command you've added. Could you share it with us, and also share the results when you execute it directly from Terminal.app, rather than from a crontab?

tog22
  • 972
  • 3
  • 12
  • 21
0

cron is deprecated in favour of launchd.

Lingon is a great little tool for setting up launchd agents; it used to be free but appears to now be $3.

Wikipedia has a good launchd page describing all the keys and the launchctl tool you use to activate/deactivate them.

chrish
  • 980
  • 1
  • 6
  • 9
0

Adding au BufEnter /private/tmp/crontab.* setl backupcopy=yes to vimrc fixed it for me. See here:

http://vim.wikia.com/wiki/Editing_crontab

mtl
  • 1
-1

I saw this same issue on OSX. The answer is to run as root using the sudo command, e.g.:

sudo crontab -e

I got that idea from Gökhan Barış Aker above.