Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

MAILTO=""
* * * * * ~/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
add comment

2 Answers

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
1  
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
add comment

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
add comment

Your Answer

 
discard

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.