Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
telnet hangs

Posted by kannarv1 (sivga1), 11 May 2007
hi
here is the expect script to telnet into a system .it succesfully telnets into the systembut when it matches

"Escape character is '^]'.^M" it hangs.. not sure why this happenning .

expect output

. 10.55.192.9 is alive ...
$ /bin/telnet 10.55.192.9^M
Trying 10.55.192.9...^M
Connected to 10.55.192.9.^M
Escape character is '^]'.^M

/bin/telnet 10.55.192.9^M
/bin/telnet 10.55.192.9^M
/bin/telnet 10.55.192.9^M
/bin/telnet 10.55.192.9^M


expect script

proc opentelnet{ tipaddr tPrompt tLogin tPasswd } {
     global      TELNET SESSION_CONNECTED TIMEOUT

     set func "opentelnet"
     
     set timeout $TIMEOUT
     send -- "$TELNET $tipaddr \r"
     #spawn $TELNET $tipaddr
       
     while (1) {
           expect {
                 "Last *\n"  {
                       continue
                 }
                 "ogin: "  {
                       send -- "$tLogin\r"
                       dbgLog 5 $func  "1. Send login name $tLogin ..."
                       continue
                 }
                 "assword: "  {
                       send -- "$tPasswd\r"
                       dbgLog 5 $func  "2. Sent passwd name ..."
                       break
                 }
                 "unknown host" {
                       errLog $func   "3. Unknown host $thost"
                       return -1
                 }
                 "*incorrect input"  {
                           errLog $func   "4. Login failed (invalid login name or passwd) ... "
                       return -1
                 }
                 "*incorrect"  {
                           errLog $func   "5. Login failed (invalid login name or passwd) ..."
                       return -1
                 }
                 timeout {
                           errLog $func   "6. Failed to establish telnet session with tipaddr ... host: $ipaddr"
                       return -1
                 }
             }
     }

     return 0
}




can you any one tell me why is this happenning.I even had a return when i matched Escape character is but dint help.

thnaks for all the help



Posted by admin (Graham Ellis), 11 May 2007
As far as I can see, you "continue" when you get Last.... and so thet goes back into expecting more.  nothing else matched, so you get a timeout ....

Since all the resopnses come in order, why not write a series of individual expects rather than putting them all into an infinite loop - much cleaner, easier to follow, easier to debug!

Posted by kannarv1 (sivga1), 11 May 2007
thanks graham even if i match and did continue it dint work th eproblem is

send: sending "/bin/telnet 10.55.192.9\r" to { exp28 }

expect: does "" (spawn_id exp2 match glob pattern "*ogin*"? no
"unknown host"? no
"*assword*"? no
"*]: "? no
"*incorrect input"? no
"*Unknown command"? no
"*Incomplete command"? no
"*Invalid input"? no
"*incorrect"? no

$ /bin/telnet 10.55.192.9

expect: does "$ /bin/telnet 10.55.192.9\r\n" (spawn_id exp2 match glob pattern "*ogin*"? no
"unknown host"? no
"*assword*"? no
"*]: "? no
"*incorrect input"? no
"*Unknown command"? no
"*Incomplete command"? no
expect: does "$ /bin/telnet 10.55.192.9\r\nTrying 10.55.192.9...\r\n" (spawn_id exp2 match glob pattern "*ogin*"? no
"unknown host"? no
"*assword*"? no
"*]: "? no
"*incorrect input"? no
"*Unknown command"? no
"*Incomplete command"? no
"*Invalid input"? no
"*incorrect"? no

Connected to 10.55.192.9.
Escape character is '^]'.

expect: does "$ /bin/telnet 10.55.192.9\r\nTrying 10.55.192.9...\r\nConnected to 10.55.192.9.\r\nEscape character is '^]'.\r\n" (spawn_id exp2 match glob pattern "*ogin*"? no
"unknown host"? no
"*assword*"? no
"*]: "? no
"*incorrect input"? no
"*Unknown command"? no
"*Incomplete command"? no
"*Invalid input"? no
"*incorrect"? no




nConnected to 10.55.192.9.\r\nEscape character is '^]

device does not send the login prompt.. so the expect scripts times out ..

but i can login to the device and everything works fine .

iam invoking the script froma a C program ..when i invoke the script seperately its fine ..


not sure why the login prompty is not coming





Posted by kannarv1 (sivga1), 11 May 2007
why does it hang after
hangs after the "Escape character is '^]'"

iam runningthe script on solaris

Posted by admin (Graham Ellis), 12 May 2007
Err ... the log doesn't look like it comes from quite the same code as the source you posted earlier.  So it's kinda hard to look for the bug.  I do note that you seem (from the log) to be looking for the ^] FOLLOWED BY A SPACE which isn't there on what telnet sends, and that would cause a hangup ...



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho