pbrooks@mentorg.com (Phil Brooks) (05/22/91)
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? -- Phil Brooks, Mentor Graphics Corporation 8005 SW Boeckman Road Wilsonville, OR 97070-7777
pbrooks@mentorg.com (Phil Brooks) (05/22/91)
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? -- Phil Brooks, Mentor Graphics Corporation (phil_brooks@mentorg.com) 8005 SW Boeckman Road Wilsonville, OR 97070-7777 (503) 685-1324
merlyn@iwarp.intel.com (Randal L. Schwartz) (05/23/91)
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'..."====/