Justin | 5 May 2008 16:09

lock a file

Hello!

Is it possible to let nano lock the file which is opened for write
access on other session? On our server there was an accident where two
admins has opened the same file on discarded the changes of the other
with writing his own. Could this be avoid?

Thanks,
justin

_______________________________________________
Help-nano mailing list
Help-nano <at> gnu.org
http://lists.gnu.org/mailman/listinfo/help-nano
Justin Lecher | 5 May 2008 16:09
Picon
Picon
Favicon

lock a file

Hello!

Is it possible to let nano lock the file which is opened for write 
access on other session? On our server there was an accident where two 
admins has opened the same file on discarded the changes of the other 
with writing his own. Could this be avoid?

Thanks,
justin

--

-- 
Justin Lecher
Institute for  Neuroscience and Biophysics
INB 2 - Molecular Biophysics II
Research centre Juelich GmbH,
52425 Juelich,Germany
phone: +49 2461 61 5385

_______________________________________________
Help-nano mailing list
Help-nano <at> gnu.org
http://lists.gnu.org/mailman/listinfo/help-nano
Trevor Cordes | 6 May 2008 14:34
Picon

Re: lock a file

On  5 May, Justin Lecher wrote:
> Hello!
> 
> Is it possible to let nano lock the file which is opened for write 
> access on other session? On our server there was an accident where two 
> admins has opened the same file on discarded the changes of the other 
> with writing his own. Could this be avoid?

I wrote a wrapper script to do something like this.  YMMV!  Works for me
on recent Linux using recent perl (all Fedora 8).  Just always run using
this new command and you'll always be warned!

Enjoy!

cat /usr/local/script/pc
#!/usr/bin/perl -w
# (c) 2008 Trevor Eaton Cordes  nano <at> tecnopolis.ca
# GPLv2, credit notice must be retained

use File::Basename;
use File::PathConvert qw(realpath);

$f=$ARGV[0] or die "Usage: pc file-to-edit\n";
$fbase=basename($f);
$freal=realpath(($f=~m#^/#?'':"$ENV{PWD}/").$f) or die;

$m='';
open(PS,'ps -efww|') or die;
while(<PS>) {
  if (m#^\S+\s+(\d+).*?\s+\d\d:\d\d:\d\d\s+nano(?:\s+-\S+)*\s+((?:/[^/]*?)*?$fbase\b)#) {
(Continue reading)


Gmane