14

I am trying to setup a cron on my mac, but it seems that it never finishes creating a crontab for my user. I open terminal and enter:

$ crontab -e 

Which returns this:

crontab: no crontab for jjmay - using an empty one




















~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"/tmp/crontab.rBdeP6yv1U" 0L, 0C

And then it waits there until I close out of the window, I have let it go for as long as 20min. I open another terminal window to check for the creation of my crontab and I get nothing.

$ crontab -l 
crontab: no crontab for jjmay

Any ideas on why I cannot create this, or if I can manually create my crontab so I can edit it?

2
  • It's been awhile since I messed with crontab files in OS X, but my guess is that this: "/tmp/crontab.rBdeP6yv1U" 0L, 0C is indicating you're either not in the correct directory or don't have permissions to write to that directory. What is the directory that you are in when typing "crontab -e"? JDB
    – JDB
    Oct 19 '10 at 19:53
  • @JDB thank you. I wasn't aware I would have to be in a specific dir., I was just in my default dir when I opened terminal, just my default User directory. /Users/<my_username>/
    – Jage
    Oct 20 '10 at 19:54
25

This isn't about the editor, it's about user permissions. First become root:

sudo su -

Then edit the crontab for the proper user:

crontab -u username -e

After saving the file, can verify that it saved properly by running this:

crontab -u username -l
2
  • 1
    This solution worked for me. A variant which surprisingly didn't work for me was: sudo crontab -u username -e Sep 16 '15 at 3:23
  • Babas-MBP:~ root# crontab -u baba -e crontab: no crontab for baba - using an empty one crontab: "/usr/bin/vi" exited with status 1 Babas-MBP:~ root# crontab -u baba -l crontab: no crontab for baba
    – barclay
    Oct 8 '20 at 13:57
7

I have encounter this problem just now. While trying to solve the problem, I was referred here form Google. Anyway, here is how I solved it.

use

crontab -e

which you have done right.

Press 'i' to insert your cronjob. For example,

1 * * * * /Users/Wong/Documents/abc.command

~

Remember to press return after the line. If you don't press return it will be like this

1 * * * * /Users/Wong/Documents/abc.command

Press ESC and type in :wq to save and exit the file. It should says "crontab: installing new crontab"

I realised that if you don't press return after your line, it won't save the whole thing.

Hope it helps.

3
  • Thanks. I kept exiting with :q! while your solution with :wq made the whole difference.
    – KeitelDOG
    Apr 13 '19 at 21:03
  • 1
    Welcome. :q! allows you to quit without saving while :wq writes to file before quiting. Apr 16 '19 at 1:17
  • I catch up with VIM commands, so now I know a lot of things that I was supposed to know!
    – KeitelDOG
    Apr 16 '19 at 4:57
2

The window it's showing is a vi editor. On traditional unix systems, vi is the default editor; it looks like Mac OS X has kept that tradition.

Set the EDITOR and VISUAL environment variables to the name (full path, if it's not in $PATH) of your favorite editor. E.g.

export EDITOR=emacs VISUAL=emacs
crontab -e

This setting should go into your ~/.profile (assuming that Mac OS X does read that file when you log in; if there is an OSX way of defining environment variables for a whole session, you can define them there).

1

Closing the terminal window is not going to make the crontab save.

Since it's using vim to create the file, look up how to use VIM and go from there.

launchd is the (Apple) preferred method in 10.5 and 10.6, but you didn't ask about that, just how to get the crontab created.

0

It's my solution: first modify your editor. export EDITOR=vim then modify .vimrc autocmd filetype crontab setlocal nobackup nowritebackup it will work.

2
  • What does this do? I for one would be very wary about changing configuration files on the say-so of some anonymous stranger on the interent who doesn't even explain what the changes are supposed to do. Aug 13 '15 at 22:33
  • Sorry about that. I have meet this problem before, then I google it get this method, but I can't find the origin post. So I just post this method, it worked for me. And you can also google this method to know why it works? Next time I will improve my answer. Sorry for my bad English.
    – Pegasus
    Aug 30 '15 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.