[Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED]

Kim Holburn kim at holburn.net
Tue Nov 27 13:22:09 PST 2007


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