[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
Tue Nov 27 16:03:02 PST 2007


Hi,

Thank you all for your responses. :--)  I love these lists.  They are so much
better than vendor support or maintenance contracts.  ;--)

I actually do use Net::Z3950 in the rest of the script but I didn't include
it in the part of the code that I sent to this list.  The rest of my code
(>1000 lines) uses that package to do many test on the zservers, download the
data and then I validate the data using another XML package.  I didn't think
that this list would like to see all that bit.  Especially in an email.  ;--)

It's funny that I tried the exact code that Jepri mentioned but I still got a
hang.  IE.

	while (($results = <ZPING>) || (sleep(60) != 60) )

I *think* that problem is that ZPING doesn't fail it just waits for a very
long time until the firewall or router sends back a message that you can't
connect.

My problem is testing to see if I can get to the internet to see if it is our
problem, such as our ISP connection to the internet being down, rather than
some of the zservers being down.  I use to use PING to test access to the
external world but our ISP blocked this in their firewall.  It *was* the
easiest solution.  If pinging two external gateways failed then it is our
problem and so I didn't try to connect to the other 27 zservers.

However, I like the fact that Net::Ping can use TCP and not ICMP (or UDP?).
I think I will try this package to ping the zservers using TCP and their
zserver port.  Z3950 is based on TCP so hopefully this should work.  I'll let
you know how I go.

Thank you all for your very, very helpful responses.


John

> -----Original Message-----
> From: Kim Holburn [mailto:kim at holburn.net] 
> Sent: Wednesday, 28 November 2007 8:22 AM
> To: Jepri
> Cc: Hockaday John; canberra-pm at pm.org
> Subject: Re: [Canberra-pm] How to exit a hung pipe to a shell 
> command [SEC=UNCLASSIFIED]
> 
> 
> Net::Ping doesn't only work with ICMP.  It can use TCP and 
> UDP as well.
> 
> It would be better in this case to try a TCP connection to the port  
> rather than ICMP.  ICMP will tell you if the host is reachable by  
> ICMP packets.  a net::ping to the port will tell you if the port is  
> open.
> 
> On 2007/Nov/27, at 10:04 PM, Jepri wrote:
> 
> > Z39.50 is an ancient protocol used to access library catalogues.   
> > It has nothing to do with ICMP.
> >
> > http://en.wikipedia.org/wiki/Z39.50
> >
> > There are more things on heaven and earth, horatio, than 
> are dreamt  
> > of in your philosphy ;)
> >
> >
> > Kim Holburn wrote:
> >> Have you tried CPAN Net::Ping?  Why not do it all in perl?
> >> Kim
> >> On 2007/Nov/16, at 4:48 AM, <John.Hockaday at ga.gov.au>   
> >> <John.Hockaday at ga.gov.au> wrote:
> >>> 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
> >>> _______________________________________________
> >>> Canberra-pm mailing list
> >>> Canberra-pm at pm.org
> >>> http://mail.pm.org/mailman/listinfo/canberra-pm
> >> --
> >> Kim Holburn
> >> IT Network & Security Consultant
> >> Ph: +39 06 855 4294  M: +39 3494957443
> >> mailto:kim at holburn.net  aim://kimholburn
> >> skype://kholburn - PGP Public Key on request
> >> Democracy imposed from without is the severest form of tyranny.
> >>                            -- Lloyd Biggle, Jr. Analog, Apr 1961
> >> _______________________________________________
> >> Canberra-pm mailing list
> >> Canberra-pm at pm.org
> >> http://mail.pm.org/mailman/listinfo/canberra-pm
> 
> --
> Kim Holburn
> IT Network & Security Consultant
> Ph: +39 06 855 4294  M: +39 3494957443
> mailto:kim at holburn.net  aim://kimholburn
> skype://kholburn - PGP Public Key on request
> 
> Democracy imposed from without is the severest form of tyranny.
>                            -- Lloyd Biggle, Jr. Analog, Apr 1961
> 
> 
> 
> 


More information about the Canberra-pm mailing list