1832212 Members
2428 Online
110041 Solutions
New Discussion

vi editor

 
Rushank
Super Advisor

vi editor

Hi,

I want to restrict multiple administrators simelteneously edit a single file. Is there any way I can do it in vi? My main concern is multiple (including remote) admins try to umdate DNS hosts file. I want this file to be open by only one admin at a give point of time.

7 REPLIES 7
Craig Rants
Honored Contributor

Re: vi editor

I don't know of anything of hand, I assume you are looking for something to perform like vipw where the file is locked when someone is editing it. You may have to write your own binary. You may try to get your hand on the vipw source code to see what they've done.

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
harry d brown jr
Honored Contributor

Re: vi editor

A baseball bat is your only option. Or you could use SCCS to control revision changes, which is something I've used in the past.


live free or die
harry
Live Free or Die
Mark Greene_1
Honored Contributor

Re: vi editor

install vim. it still allows concurrent sessions, but it at least has the benefit of displaying a warning message if you are editing a file while another vim session has it open as well.

HTH
mark
the future will be a lot like now, only later
Craig Rants
Honored Contributor

Re: vi editor

Didn't think about Harry's option, that could be a possibility. We have some sort of revision control software here, where you have to check a script/file out edit it, then check it back in... What a pain, obviously I almost never use it which defeats the point of having it...

C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Rushank
Super Advisor

Re: vi editor

Thanks ... For now vim looks like better option.!
Steven Sim Kok Leong
Honored Contributor

Re: vi editor

Hi,

The other way is to write a wrapper script for vi (below is a simplistic script which assumes only one parameter and it can be enhanced to your needs) eg.

# mv /usr/bin/vi /usr/bin/vi.bin
# vi /usr/bin/vi

#!/sbin/sh
if [ -e /tmp/$1.vilck ]
then
echo "Someone is currently editing $1. Please try again later..."
exit 1
else
touch /tmp/$1.vilck
/usr/bin/vi.bin $1
fi

Hope this helps. Regards.

Steven Sim Kok Leong
Steven Sim Kok Leong
Honored Contributor

Re: vi editor

Hi,

I forgot to remove the lock "semaphore" upon exit. Revised as follows:

#!/sbin/sh
if [ -e /tmp/$1.vilck ]
then
echo "Someone is currently editing $1. Please try again later..."
exit 1
else
touch /tmp/$1.vilck
/usr/bin/vi.bin $1
rm -f /tmp/$1.vilck
fi

Hope this helps. Regards.

Steven Sim Kok Leong