Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: chat and perl for new user Keywords: perl chat Message-ID: <1991May23.161215.23126@iwarp.intel.com> Date: 23 May 91 16:12:15 GMT References: <1991May8.184943.12338@iwarp.intel.com> <1991May22.164333.24783@mentorg.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 44 In-Reply-To: pbrooks@mentorg.com (Phil Brooks) In article <1991May22.164333.24783@mentorg.com>, pbrooks@mentorg (Phil Brooks) writes: | I am new to perl and new to chat and in search of an example using | both. Say I wanted to do something like connect to a sendmail | daemon on another machine and see if it is alive. I can do this | using telnet as follows: | | $ telnet ptd 25 | Trying 137.202.54.21... | Connected to ptd. | Escape character is '^]'. | 220 ptd-hub.PTD.MENTORG.COM HP Sendmail (16.6/15.5+IOS 3.20) ready at Wed, 22 May 91 09:36:35 -0700: | helo | 250 ptd-hub.PTD.MENTORG.COM Hello (pbrooks.ptd.mentorg.com), pleased to meet you | quit | 221 ptd-hub.PTD.MENTORG.COM closing connection | Connection closed by foreign host. | $ | | From what I have seen, it looks like chat would be a good way to do this. | The timeout value would get around problems with hung servers etc. | Can someone post an example? require 'chat2.pl'; &chat'open_port("ptd", 25) || die "No connect: $!"; if (&chat'expect(15, '^220', 1)) { # if I see the 220 in 15 seconds, return 1 print "he's a happy camper\n"; } else { print "no go, joe.\n"; } &chat'close(); See, it's pretty simple. If you don't have chat2 (still in alpha), write me. The timeout on the open connection occurs during &chat'open_port, so you may have a 30 second wait at that point. It'd return the bad value to trigger the "die", though. print 1 ? "Just another Perl hacker," : " with chat2 du jour :-)" -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/