[Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED]
John.Hockaday at ga.gov.au
John.Hockaday at ga.gov.au
Thu Nov 15 19:48:56 PST 2007
Hi All,
I have a PERL pipe that calls a c++ binary called
"/public/data/asddgate/isite/current/bin/zping". It tries to ping an
external zserver using the hostname and port parameters. If the ping works
it returns something like:
Z39.50 server at www.ga.gov.au on port 6668 is alive.
and then exits the pipe.
Sometimes it can't zping because the zserver is down or the zping command is
not allowed through a firewall so the pipe hangs for 224 seconds.
There is an option of -t NN which sets how long to wait for a response from
the zserver and I set this to 60 seconds (zping -t 60) but this doesn't seem
to work when the pipe hangs.
I have tried to overcome this by using a combination of PERL while and sleep
but I just can't seem to get it to work. Here is a snippet of my code:
#################################################################
#!/opt/csw/bin/perl
###################
# sleep for 60 seconds or zping
###################
$hostname = shift;
$port = shift;
$zping_cmd = '/public/data/asddgate/isite/current/bin/zping';
my ($alive);
open (ZPING, "$zping_cmd -t 60 $hostname $port 2>&1 |")
or die "Cannot open zping: $!";
while (($results = <ZPING>) || (sleep(60) != 60) ) {
print "$results\n";
if ($results =~ m/is alive/) {
$alive = 1;
print "$results\n";
last;
}
}
print "closing ZPING and alive = $alive\n";
close ZPING;
#################################################################
Am I doing this correctly or is there some other way to break this pipe after
waiting for a set time and still continue with the code? I tried alarm but
it exits the script and I want to keep on processing.
Thanks.
John Hockaday
Geoscience Australia
GPO Box 378
Canberra ACT 2601
(02) 6249 9735
http://www.ga.gov.au/
john.hockaday\@ga.gov.au
More information about the Canberra-pm
mailing list