KpyM Telnet/SSH Server - Forum
Expect & KTS
GlennS Expect & KTS
 
I am trying to use EXPECT on the *Nix server to connect and run processes on the PC.
Using Pipe_mode=0, the login would work, but (I believe) because of the graphics mode, EXPECT could not see the ">" prompt response.
Using Pipe_mode=1, the initial connection welcome message wasn't displayed, and Expect still couldn't see the prompt.

Has anyone successfully used Expect with KTS? any suggestions?
thanx
GlennS


Kroum Grigorov
 
> Using Pipe_mode=1, the initial connection welcome message wasn't displayed, and Expect still couldn't see the prompt.

Does it work OK when you use your ssh/telnet client instead the Expect script?
You might try to hit enter couple of times after you login in your expext script and then check for the prompt.

Kroum


GlennS
 
I ended up having to change EXPECT to look for more than just ">" as an initial prompt, then it would take just the ">" prompt.

Thanx much for the great work (still looking forward to public/private keys ;)

see fix below:


---------------------- winssh.exp
#!/usr/bin/expect
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
}
}
if {$argc < 2 || $argc > 3} {
puts "usage: winssh.exp <ip_address> <command_file> \[command_sleep\$
exit 1
}

# Getting arguments
set host [ lindex $argv 0 ]
set password "password"
set cmdfilename [ lindex $argv 1 ]
if {$argc == 3} {
set cmdsleep [ lindex $argv 2 ]
} else {
set cmdsleep 0
}

# Starting connection
set username "user"
set prompt ">"
set cmdfile [ open "$cmdfilename" "r" ]

# timeout 40 works, but slow

set timeout 30
spawn ssh $username@$host
match_max 100000
#
# If successful, the "user>" prompt will allow the cmdfile.WIN to proceed
## note KTS "allusers.bat" has a cd %USERPROFILE% line in it.
# If 'route to host' is found, EXIT-1 will tell the wrapper to abort that PC attempt
# If 'timeout (10sec)' is found, it throws EXIT-2, which will be interpretted by wrapper as "try Telnet"
# If 'Refused' is found, it throws EXIT-3, which will be logged for the end of the wrapper
# routine, and suggest retry.
#

while 1 { expect {
"(yes/no)? " {send -- "yes\r"}
"assword: " {send -- "$password\r"}
"user>" {break}
"route to host" {send_user "PC doesn't Exist\r"; exit 1}
timeout {send_user "Unable to connect\r"; exit 2}
"refused" {send_user "PC Isn't ready, Logging as refused.\r"; exit 3}
} }
while {[gets $cmdfile cmdline] != -1} {
expect "$prompt"
send -- "$cmdline\r"
sleep $cmdsleep
}

expect eof
close $cmdfile
-----------------------------------------------------

-----------------------------------------------------file.win contains (or anything else):
cd \
dir
exit
-----------------------------------------------------

syntax:
winssh.exp [ip] file.win


busilu
 
SSH server has a talent list to get data along with the blogs that used to maintain the forum among these kits. Download the registration part to get the firms about essay writers service the company that has work among the partition to used registration path.


 

© 2007 - 2008 Kroum Grigorov
Powered by phpBB © 2001, 2005 phpBB Group