Link to home
Start Free TrialLog in
Avatar of kccole
kccole

asked on

File Locking for editing ??

Hello,

    I'm running on a Sun SPARCstation 5 (SunOS 5.5.1) can
someone please tell me the best way to control this situation: There are several files that several people need to change concurrently (using vi and emacs).  These 3 people
are members of a unique unix group.  How can we ensure that
we are not editing the same file at the same time? This is not source code and we don't want to use SCCS or any other
source control system - We're looking for some file locking
mechanism; e.g., John is ready to edit file "foo.doc" he
executes <unix.file.locking.command> he then edits the document; after finished with edits he unlocks the file <unix.file.locking.command -u>.

Thanks !

kcc
Avatar of ozo
ozo
Flag of United States of America image

lock="$NEWSCTL/LOCKxxx"         # modify name as appropriate
ltemp="$NEWSCTL/L.$$"
echo $$ >$ltemp
trap "rm -f $ltemp ; exit 0" 0 1 2 15
while true
do
        if ln $ltemp $lock
        then
                trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
                break
        fi
        sleep 30
done

Avatar of kccole
kccole

ASKER

Thanx for your reply but unfortunately I'm left with too many questions as to what each line of code does exactly and how it can be used in the example I supplied (in other words please
make it more idiot proof! with comments for code and an explanation of how to implement/execute when needing to edit the
 file.

Thanx Much!
kcc
ASKER CERTIFIED SOLUTION
Avatar of dhughes111797
dhughes111797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
alias vi to vi-lock (for example)
shell script for vi-lock (not security proofed):

#! /bin/sh
file=$1
chmod g-w $file
chmod o-w $file
/bin/vi $file
chmod g+w $file
chmod o+w $file
Avatar of kccole

ASKER

ahoffman,

    Doesn't your script work only if the owner of the file isn't
a possible editor of the file ? e.g.,

    unix id=sammi   group id=sammi

Sammi decides to add 3 other user's (unix id's) to his group:

    group sammi ==>  sammi, franki, noel, pransor

If franki executes your script and edits a common file
having the permission of 775 (before executing it) then
what will prevent Sammi from editing the same file at the same
time, thus corrupting the changes franki has made?

thanx!
kcc
Avatar of kccole

ASKER

Adjusted points to 75
Avatar of kccole

ASKER

Hello All,
 
    I've just learned of a utility called "led" on my system
that allows the very thing I need to do.  I just thought I'd poll the readers to see if anyone else knew of its existence too and
if so why do home grown stuff when something is already there to
use??

Thanx Again.,
kcc
never heard of it.. Are you sure it's not a local thing? (It's not
on any of our Solaris2 boxes)