Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > can *awk manage telnet sessions?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 26th February 13:40
jnh
External User
 
Posts: 1
Default can *awk manage telnet sessions?



Hi. I wonder if awk (or some of its ?awk's versions) can be used to
manage a telnet session as with tcl/expect. I have digged on inet and
newsgroups but i have not found examples using pipes with telnet.


===
BEGIN {

scommand="telnet 10.0.14.10"
while ((scommand |& getline)>0) {
print $0 # to debug
if ($0~"login") {print "user" |& scommand}
if ($0~"Password") {print "password" |& scommand}
if ($0~"mymachineprompt") {print "commands_to_execute" |& scommand}
}
close (scommand)
}
===

if it's executed with awk -f test.awk (on Red Hat 7.3 and
targeting a Sun box; gawk version 3.1.1) I obtain the following lines,
but the "login:" never appears.

===
Trying 10.0.14.10...
Connected to 10.0.14.10.
Escape character is '^]'.


SunOS 5.8
===

Have I made some mistake? Can this be perfomed with awk (or gawk)?
If not... what would be the best alternative, perl or tcl/expect?

I'd be very appreciative to any answer. Thanks in advance.
  Reply With Quote


  sponsored links


2 26th February 13:40
External User
 
Posts: 1
Default can *awk manage telnet sessions?



What you want can undoubtedly be done with tcl/expect.

It might work with gawk 3.1.2 and 3.1.3; see the doc which tells you how
to make gawk use ptys instead of pipes for communication. Basically,
it's

BEGIN {
scommand="telnet 10.0.14.10"
PROCINFO[scommand, "pty"] = 1

# rest of code as before
}

No guarantees though!

Good luck,

Arnold


--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 530 688 5518
Nof Ayalon Cell Phone: +972 51 297-545
D.N. Shimshon 99785 ISRAEL
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666