Mac Osx Set Default Editor For Crontab

Active8 months ago
For

'Joe's own editor' does not come naturally to me. How do I change to using nano or vim?

Also, rather than use crontab -e (with an editor directly), I suggest that you SAVE your crontab in a file on disk, by entering command crontab -l > my_cron.orig. To use and change an editor to edit your text message, set the variable EDITOR to the pathname of the vi / vim binary file. You need to use export or set command for the same purpose. Many Linux / UNIX command read shell EDITOR environment variable to determine which editor to use for editing a text file. You can test this by typing: crontab -e Looking beyond Mac OS X, this should work in Linux as well Change & Set the Default crontab Editor - Most hardcore command line users and unix geeks love vi, but I prefer nano. However, I was never able to get crontab to work under Mac OS X 10.6, so. In this tutorial I’ll go with Apple's suggestion and show you how to run your Unix shell scripts and commands with the MacOS launchd facility using the launchctl command.

I've tried

but it doesn't seem to be respected. I'd like visudo to respect this as well.

Gilles
573k139 gold badges1184 silver badges1695 bronze badges
wmarbutwmarbut

migrated from raspberrypi.stackexchange.comJul 10 '12 at 12:47

This question came from our site for users and developers of hardware and software for Raspberry Pi.

3 Answers

To change the default editor at the system level:

and then follow the onscreen prompts.

Gilles
573k139 gold badges1184 silver badges1695 bronze badges
Editor
Steve RobillardSteve Robillard

The way to change the default editor for your account is to set the EDITOR environment variable. If that doesn't work for you, you've done something unusual. Check that you haven't also defined VISUAL, or if you have, give the two variables the same value (see VISUAL vs. EDITOR – what’s the difference?). Add these lines to your ~/.profile (note: not to ~/.bashrc):

Under the Debian policy, all programs are supposed to support EDITOR and VISUAL to set the default editor.

Under Debian and derivatives, you can use the alternatives mechanism to set the system-wide default editor, as mentioned by Steve Robillard: run update-alternatives --config editor as root.

Anthony Geoghegan
8,4565 gold badges42 silver badges56 bronze badges
GillesGilles
573k139 gold badges1184 silver badges1695 bronze badges

The solution mentioned above works, but it isn't scriptable. If you want to do this in a scriptable (non-interactive) fashion, you should use --set:

You can get a list of the choices with:

JoelJoel

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

Active7 years, 7 months ago

I'm trying to get familiar with cron jobs, and I think I get the basic idea (scheduling, syntax, etc), But, I can't seem to get it right on my mac with Terminal - where exactly do I find the Crontab? How should I reference the paths to scripts?

What I'm trying to do is hit a php script on a remote machine (http://...) - Is that possible at all?

AdamAdam

6 Answers

To get started with launchd (instead of cron) you'll want to first create an empty .plist file, for example local.mytask.plist and put it somewhere. ~/Library/LaunchAgents is probably a good place. Open that in text editor and copy in the code below

Then 'activate' the file from the command line:

To make it load automatically, create a ~/.launchd.conf file with the same line (minus sudo launch)

The above instructions above have been copied from www.davidlanier.com and reposted here for your reference.

saschabeaumontsaschabeaumont
20.4k4 gold badges56 silver badges83 bronze badges

Type crontab -e to edit your cron table and crontab -l to list the current contents.. Type man 1 crontab for more info on that command and man 5 crontab for more info on the cron table file format.

Mac Osx Set Default Editor For Crontab -e

For example, to download the stackoverflow page every day at 10:00a, run crontab -e, enter this line, and then save/quit. The output will be written to a file in your home directory.

Ryan BrightRyan Bright

On the off chance that someone else fighting with cron on Snow Leopard stumbles across this, I will dredge up this old thread.

Yes, launchd is supposed to replace cron, but in fact it can't do certain things cron can.

Cron is not integrated well. If it sends a message, it ends up in /var/mail/user_name which of course Apple Mail knows nothing about.

crontab -e throws up saying 'temp file must be edited in place'. Apparently vim is not vi compatible. You can then do crontab '< /tmp/crontab.whatever' (look in /tmp and see what name is actually used) and it will end up in the right place and, assuming you didn't make a typo, will work.

Yes, it took a while to sort this all out :(

CritterCritter

launchd is powerful, but you really don't want to write the plist yourself. Get Lingon. It's an open-source, really well-designed GUI for creating and managing your system's launchd tasks.

BenBen

Cron has been replaced by launchd since 10.4. You should probably write your tasks using this unless you plan on porting them to Linux/Unix systems at some point.

If you do decide to go with cron anyway, try typing crontab -e or sudo crontab -e. These will give you different crontab files, the former for the user you're currently running as and the latter for the root user.

'Hitting' a URL can be accomplished a lot of ways. Depending on the local script that you are using to 'hit' it, you could use some of the language's built-in methods/classes. For instance, a Ruby script would use net/http but you could try curl as well if you're just writing a bash script. Do man curl to find out more, but the basic command is just curl http://google.com.

Topher FangioTopher Fangio
13.9k14 gold badges55 silver badges86 bronze badges

You no longer want to be using cron. As others have already stated, it has been replaced by launchd and launchd is clearly going to be the future on Mac OS X.

MacTech Magazine has recently been doing a series of articles on launchd and I would highly recommend reading them. I know I have certainly learned a lot.

September, 2009 (Volume 25, Issue 9)25.09 MacEnterprise: launchd for Lunch

October 2009, (Volume 25, Issue 10)Snow Leopard, Launchd, and LunchMore launchd recipes, and a look at changes in Snow Leopard

There have been other articles in MacTech and I would suggest searching their site.

ericgericg

Mac Os X Set Default Editor For Crontab

5,2774 gold badges33 silver badges60 bronze badges

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