From John.Hockaday at ga.gov.au Thu Nov 15 19:48:56 2007 From: John.Hockaday at ga.gov.au (John.Hockaday at ga.gov.au) Date: Fri, 16 Nov 2007 14:48:56 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] Message-ID: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> 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 = ) || (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 From nick at cambia.org Thu Nov 15 20:12:11 2007 From: nick at cambia.org (Nick dos Remedios) Date: Fri, 16 Nov 2007 15:12:11 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> Message-ID: <5172D90F-FB34-40AF-878F-C9A0E41BFB8B@cambia.org> Sounds like you need to use alarm... http://perldoc.perl.org/functions/alarm.html see the example at the bottom of the page. Nick On 16/11/2007, at 2:48 PM, 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 = ) || (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 > -- Nick dos Remedios nick at cambia.org http://www.cambia.org/ From jarich at perltraining.com.au Fri Nov 16 01:03:17 2007 From: jarich at perltraining.com.au (jarich at perltraining.com.au) Date: Fri, 16 Nov 2007 20:03:17 +1100 (EST) Subject: [Canberra-pm] OSDC 2007's Fabulous Keynotes! Message-ID: <20071116090317.6E4CCA8F15@teddybear.perltraining.com.au> Dear Canberra PM members, Final reminder! Register now for the Open Source Developers' Conference 2007: http://www.osdc.com.au/registration/index.html Key information: 26th November - Tutorials 27th - 29th November - Technical programme 28th November - Google Conference Dinner Royal on the Park Hotel Cnr Alice & Albert Streets Brisbane CBD Queensland Each full registration ($325) includes one dinner ticket (until sold out). Single day tickets are also available for $150. Check out our tutorial program at http://www.cgpublisher.com/conferences/107/web/program-detail.html Keynote talks this year include: Rusty Russell: "C: A Humbling Language" ------------------------------------------------------------------ Some languages have beautiful constructs and elegant power. Others have novelty and fresh ideas. Surely C is a sometimes-necessary evil, and been around so long that there's nothing new to discover about it? So what kind of retarded masochist would select C as their language of choice? And why? Rasmus Lerdorf: "Exploring the Broken Web" ------------------------------------------------------------------ XSS and XSRF has been a thorn in the side of the web for years now. Rasmus will show some very common mistakes people make and tie it to the real world by showing a vulnerability in actual sites. Paul Fenwick: "An Illustrated History of Failure" ------------------------------------------------------------------ The average individual is given little scope for failure, at least not the type that really matters. The opportunity for catastrophic failure, that influences nations or continents, has been traditionally reserved for royalty, parliament, and others in a position of great leadership. However in recent times we have developed a profession who have the opportunity to fail like never before. A profession that can make mistakes that are so monumental, so wide-reaching, and so costly they can shake civilisation to its very core. This elite group, rarely seen by every day society, are the foundation upon which modern society depends. The few, the proud, the Software Developer. Join us for a voyage of discovery, as we travel back through history to some of the most monumental failures the world has ever seen. Jonathan Oxer: "Software Freedom: Pragmatic Idealism?" ------------------------------------------------------------------ The Free / Open Source Software (FOSS) community is incredibly diverse with a corresponding variety of reasons for participation. At one end of the scale is dreamy idealism, which aims to free all information for the good of mankind. At the other end is economic pragmatism, which sees Open Source as a powerful business opportunity and software development model. Is there common middle ground where both ends of the spectrum can meet? Can Free Software really can be Pragmatic Idealism? And what are we doing as a country in terms of building a sustainable local ICT industry? Be a part of this fantastic conference and help it be the best developers' conference this year! If your business would like to benefit from exposure to many of Australia's best open source developers then perhaps you should consider sponsorship. We have a wide range of sponsorship options, to find out more information please visit: http://www.osdc.com.au/sponsors/index.html Jacinta Richardson OSDC Publicity Officer From jepri at alphacomplex.org Tue Nov 27 09:30:07 2007 From: jepri at alphacomplex.org (Jepri) Date: Wed, 28 Nov 2007 04:30:07 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> Message-ID: <474C541F.8000801@alphacomplex.org> while (($results = ) || (sleep(60) != 60) ) if ($results = ) fails, you will sleep a further 60 seconds due to (sleep(60) != 60). Under unix you should get a "read failed because pipe closed" type error when zping exits. If zping doesn't exit you can try either the alarm function that nick mentioned (you might have to muck around with eval or handlers to make that work), or try non-blocking reads on your process handle. I like non-blocking reads, but they are poor for efficiency and so considered naughty. I'll let you read up on the non-blocking reads, it's fairly complex. Sorry about the delayed reply, my mail server went wrong in many ways. 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 = ) || (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 From kim at holburn.net Tue Nov 27 12:49:59 2007 From: kim at holburn.net (Kim Holburn) Date: Tue, 27 Nov 2007 21:49:59 +0100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> Message-ID: <07C75154-A246-4986-AE10-C66546EB258F@holburn.net> Have you tried CPAN Net::Ping? Why not do it all in perl? Kim On 2007/Nov/16, at 4:48 AM, 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 = ) || (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 From jepri at alphacomplex.org Tue Nov 27 09:33:42 2007 From: jepri at alphacomplex.org (Jepri) Date: Wed, 28 Nov 2007 04:33:42 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> Message-ID: <474C54F6.3030100@alphacomplex.org> Nearly forgot... there's a cpan module for z39.50. In fact, more than one: http://search.cpan.org/search?query=z39.50&mode=all HTH 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 = ) || (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 From kim at holburn.net Tue Nov 27 13:22:09 2007 From: kim at holburn.net (Kim Holburn) Date: Tue, 27 Nov 2007 22:22:09 +0100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <474C8648.4080107@alphacomplex.org> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> <07C75154-A246-4986-AE10-C66546EB258F@holburn.net> <474C8648.4080107@alphacomplex.org> Message-ID: <82410A81-D198-40AF-A1DD-D725F5C02C43@holburn.net> 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, >> 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 = ) || (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 From John.Hockaday at ga.gov.au Tue Nov 27 16:03:02 2007 From: John.Hockaday at ga.gov.au (John.Hockaday at ga.gov.au) Date: Wed, 28 Nov 2007 11:03:02 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] Message-ID: <8BD19F29B0E16E4F88277A997CD872C2396270@mail.ga.gov.au> 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 = ) || (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, > >> 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 = ) || (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 > > > > From jepri at alphacomplex.org Tue Nov 27 13:04:08 2007 From: jepri at alphacomplex.org (Jepri) Date: Wed, 28 Nov 2007 08:04:08 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] In-Reply-To: <07C75154-A246-4986-AE10-C66546EB258F@holburn.net> References: <8BD19F29B0E16E4F88277A997CD872C2396256@mail.ga.gov.au> <07C75154-A246-4986-AE10-C66546EB258F@holburn.net> Message-ID: <474C8648.4080107@alphacomplex.org> 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, > 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 = ) || (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 From John.Hockaday at ga.gov.au Wed Nov 28 14:46:18 2007 From: John.Hockaday at ga.gov.au (John.Hockaday at ga.gov.au) Date: Thu, 29 Nov 2007 09:46:18 +1100 Subject: [Canberra-pm] How to exit a hung pipe to a shell command [SEC=UNCLASSIFIED] Message-ID: <8BD19F29B0E16E4F88277A997CD872C2396277@mail.ga.gov.au> Hi All, I managed to get my script working. I used Net::Ping to connect to the zservers on the zserver port using TCP. Here are the few lines that fixed my problem. It's so simple! ;--) use Net::Ping; ... my ($p) = Net::Ping->new("tcp", 60); $p->{port_num} = $port; # Old version of Net::Ping? ++$badcount if (!$p->ping($host)); ... If the number of $badcount >= $number_servers then the ISP connection is probably down. Thanks to you all. John > -----Original Message----- > From: canberra-pm-bounces+john.hockaday=ga.gov.au at pm.org > [mailto:canberra-pm-bounces+john.hockaday=ga.gov.au at pm.org] > On Behalf Of Hockaday John > Sent: Wednesday, 28 November 2007 11:03 AM > To: kim at holburn.net; jepri at alphacomplex.org > Cc: canberra-pm at pm.org > Subject: Re: [Canberra-pm] How to exit a hung pipe to a shell > command[SEC=UNCLASSIFIED] > > > 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 = ) || (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, > > >> 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 = ) || (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 > > > > > > > > > _______________________________________________ > Canberra-pm mailing list > Canberra-pm at pm.org > http://mail.pm.org/mailman/listinfo/canberra-pm >