16

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
    Commented Oct 19, 2010 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
    Commented Oct 20, 2010 at 19:54

6 Answers 6

28

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 Commented Sep 16, 2015 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
    Commented Oct 8, 2020 at 13:57
10

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
    Commented Apr 13, 2019 at 21:03
  • 1
    Welcome. :q! allows you to quit without saving while :wq writes to file before quiting. Commented Apr 16, 2019 at 1:17
  • I catch up with VIM commands, so now I know a lot of things that I was supposed to know!
    – KeitelDOG
    Commented Apr 16, 2019 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. Commented Aug 13, 2015 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
    Commented Aug 30, 2015 at 10:55
0

This post is super old, but I wanted to ring in. I'm on mac and using crontab -e would never stick (running crontab -l after saving would result in "no crontab for ____").

The issue on my system is that I was using Visual Studio Code as an editor. I temporarily overrode VISUAL=/usr/bin/vim. Then after crontab -e it printed crontab: installing new crontab. A follow up crontab -l now prints the file that I expected to save.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .