This is an interesting proposed solution. But as the poster pointed out depends on whether they are *only* using vi, if that can be assured then you might consider using the method by which vi does its own checking on its own files. In other words check for a ".<filename>.swp" or maybe a ".<filename>.sw*" file in the directory where your file exists, if that file exists then the file is open in someone's vi session.
The real question is whether "vi" uses this swap file or whether that is a "vim" convention (which is most likely what vi is on any recent linux distro) but I don't have access to a box with "vi" while here at home, only "vim". Again this doesn't help in cases of another editor being used....... http://danconia.org david wrote: > the tricky part is the "admin who has opened up the file in 'vi' and editing > the file". this kind of manually open editing behavior is hard to track for > the locking module that you just mention. the following provides you with a > simple(not perfect at all and it's slow) method and it searches your process > table for anyone who has open the tmp.pl(you will want to change this to > the script that you want to track) in vi: > > #!/usr/bin/perl -w > use strict; > use Proc::ProcessTable; > > my $t = new Proc::ProcessTable; > > foreach my $p (@{$t->table}){ > next unless $p->cmndline =~ /vi.*tmp\.pl/; > print "Someone already editing: tmp.pl with ",$p->cmndline,"\n"; > } > > __END__ > > now if i open tmp.pl like: > > vi tmp.pl > > and then run the script, the script will print: > > Someone already editing tmp.pl with vi tmp.pl > > this method is slow and is not 100%. what happen if your admin decided to > use another editor than vi? no luck... however, i hope the above can > provide you with something to get going... > > for all of the other locking modules you mention, your OS usually have to > support the flock system call or they will not work(usually silently) > > david > > Ramprasad A Padmanabhan wrote: > > >>Hi All, >> I am writing an web application where multiple users may write into >>the same file concurrently. Also there is a probability that there may >>be an admin who has opened up the file in 'vi' and editing the file. >> >> I want to avoid this concurrent multiple opens. >>I tried a range on perl modules like IO::LockedFile, File::Flock; >>LockFile::Simple etc but all these do not enforce any lock and worst >>they lock a file even if it is already open in vi >> >>Any Help >>Ram > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]