Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Under MacOSX 10.8.2 I am able to run vim as follows in the bash shell:

/usr/bin/vim -c "normal G" -c 'startinsert' ~/.journal

If I put the exact same command in a script:

#! /bin/bash

export DISPLAY=:0
echo -n -e "\n[" `date` "]:\n\n">>~/.journal

/usr/bin/vim -c "normal G" -c 'startinsert' ~/.journal

and run the script, it also opens vim correctly.

However, if I put the script, named 01diaryscript, into crontab:

* * * * * ~/01diaryscript

vim does not open... BUT a new vim process is created with its own unique id every minute.

On the other hand, if I use the vim, also 7.3, included in the MacVim package, cron works.

Is there a way to force the vim process that is created when I run the first script in cron to be accessible?

share|improve this question

Your line in your crontab explicitely ask to launch your script every single minute of every day. And it does so as you can see in the processes.

Now why you do not see vim is because cron spawn the commands you setup in the "background". So you can not access them directly. I can't explain why vim in the MacVim package works because I do not know it.

What could work is to open either a graphical VIM or a new xterm with vim inside. Something like: xterm -e /usr/bin/vim -c "normal G" -c 'startinsert' ~/.journal

share|improve this answer
xterm would need to know what DISPLAY to open, and this environment variable is not present in cron, if there even is a display you are currently logged into, which may not be the case. Trying to run interactive applications from cron is just wrong headed. – psusi Feb 9 '13 at 22:24
@psusi I know, but that is why the person asked for. And his script is setting the display already. I am just replying to the question. – Huygens Feb 9 '13 at 22:29

cron runs command in the background, without any terminal (or X display, for that matter). Where should said output go? Show the output of random user's cron jobs on my screen? Makes no sense.

What is the problem you are trying to solve here?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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