Telnet via autoexpect is scuccessfull but when I use
the code generated via file (script.exp) of autoexpect
it fails
following is the output
1)Telnet to UUT from autoexpect
nux:~/home # autoexpect telnet 192.168.1.136 6500
autoexpect started, file is script.exp
Trying 192.168.1.136...
Connected to 192.168.1.136.
Escape character is '^]'.
M,2
S,M,0
"^],0
telnet> exit
?Invalid command
telnet> logout
E,2
'^]
telnet> '
?Invalid command
telnet> '^]'
?Invalid command
telnet> quit
Connection closed.
autoexpect done, file is script.exp
2) Code vinux:~/home # more script.exp
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Mon Oct 20 19:21:46 2003
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt"

which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don
set timeout -1
spawn telnet 192.168.1.136 6500
match_max 100000
expect -exact "Trying 192.168.1.136...\r\r
Connected to 192.168.1.136.\r\r
Escape character is '^\]'.\r\r
"
send -- "\r"
expect -exact "\r
E,2\r"
send -- "M\r"
expect -exact "M\r
=,M,0\r"
send -- "S\r"
expect -exact "S\r
=,S,0\r"
send -- "\""
expect -exact "^\]\r
telnet> "
send -- "exit\r"
expect -exact "exit\r
?Invalid command\r\r
telnet> "
send -- "logout\r"
expect -exact "logout\r
"
send -- "\r"
expect -exact "\r
E,2\r"
send -- "\r"
expect -exact "\r
E,2\r"
send -- "'"
expect -exact "^\]\r
telnet> "
send -- "'\r"
expect -exact "'\r
?Invalid command\r\r
telnet> "
send -- "'"
ia script.exp
3) I use the above script with modifications naming a file
myscript#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn telnet 192.168.1.136 6500
match_max 100000
4) The result of this script is
~
linux:~/home # ./myscript
spawn telnet 192.168.1.136 6500
linux:~/home #
5) I want to telnet to my UUT (Unit under test)
and send some commands.
6) my orignal file was as follow
I tried the spawn telnet with quots and without quotes
with \r, \n also
#!/usr/bin/expect -f
send "this\n"
send "is a test\n"
spawn telnet "192.168.1.136 6500\n"
7)Please help thanks
HZ