M
Michele Dondi
I have a *working* .sig rotation script that begins like this:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
$|++;
setsid;
# ...
# Do some administrative things like
# redirecting STDIN STDOUT and STDERR
# ...
fork and exit;
then it starts an infinite loop and writes to a fifo (creating it if
it doesn't exist).
Now I'd like to use some mechanism to prevent more than one copy of
the program to run at the same time on the same machine. The named
pipe is in my home, mounted on nfs.
I've thought of using a lockfile, but then since I can be logged at
the same time on different machines, I *think* I should write in it
the hostname, possibly along with other info.
Anyway, I've really *no* experience in these matters, so can you give
me any suggestion? Also, I'm not asking you to do the job for me, but
could you please provide some minimal code snippet?
Note: I know I've read that file creation/deletion is not atomic over
nfs, but I don't think this is really a major issue, since I'll call
the script from my .bash_profile and it's hard to imagine how there
could be race conditions...
Last, I have another request: as I said above, I want to launch my
script on login, and even if it wouldn't be a problem to have it
running as a background process when I'm not logged in, I'd rather
prefer to have it exit when I exit the shell.
I know this is not strictly speaking a Perl question, but also in this
case I'd welcome an actual code snippet.
TIA,
Michele
--
#!/usr/bin/perl -lp
BEGIN{*ARGV=do{open $_,q,<,,\$/;$_}}s z^z seek DATA,11,$[;($,
=ucfirst<DATA>)=~s x .*x q^~ZEX69l^^q,^2$;][@,xe.$, zex,s e1e
q 1~BEER XX1^q~4761rA67thb ~eex ,s aba m,P..,,substr$&,$.,age
__END__
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
$|++;
setsid;
# ...
# Do some administrative things like
# redirecting STDIN STDOUT and STDERR
# ...
fork and exit;
then it starts an infinite loop and writes to a fifo (creating it if
it doesn't exist).
Now I'd like to use some mechanism to prevent more than one copy of
the program to run at the same time on the same machine. The named
pipe is in my home, mounted on nfs.
I've thought of using a lockfile, but then since I can be logged at
the same time on different machines, I *think* I should write in it
the hostname, possibly along with other info.
Anyway, I've really *no* experience in these matters, so can you give
me any suggestion? Also, I'm not asking you to do the job for me, but
could you please provide some minimal code snippet?
Note: I know I've read that file creation/deletion is not atomic over
nfs, but I don't think this is really a major issue, since I'll call
the script from my .bash_profile and it's hard to imagine how there
could be race conditions...
Last, I have another request: as I said above, I want to launch my
script on login, and even if it wouldn't be a problem to have it
running as a background process when I'm not logged in, I'd rather
prefer to have it exit when I exit the shell.
I know this is not strictly speaking a Perl question, but also in this
case I'd welcome an actual code snippet.
TIA,
Michele
--
#!/usr/bin/perl -lp
BEGIN{*ARGV=do{open $_,q,<,,\$/;$_}}s z^z seek DATA,11,$[;($,
=ucfirst<DATA>)=~s x .*x q^~ZEX69l^^q,^2$;][@,xe.$, zex,s e1e
q 1~BEER XX1^q~4761rA67thb ~eex ,s aba m,P..,,substr$&,$.,age
__END__