LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   telnet server not reliable for expect script (https://www.linuxquestions.org/questions/linux-software-2/telnet-server-not-reliable-for-expect-script-383702/)

powah 11-16-2005 11:07 AM

telnet server not reliable for expect script
 
I installed telnet server on FC3.
"disable = no" is set in
/etc/xinetd.d/telnet

Use xinetd to start telnet
$ /etc/init.d/xinetd restart

"telnet localhost" always work manually.
I wrote an expect script to automate telnet does not work most of the time in this machine but
always work in another machine.

The expect script is:
#!/usr/bin/expect

proc info_print { str} {
send_user " ++++++++++++++++++++++++++++++++++++++++++++++++++++++"
send_user " $str"
send_user " ++++++++++++++++++++++++++++++++++++++++++++++++++++++"
}


proc run_remote { {server} {user} {pass} {params} } {
set timeout 60
set res [spawn telnet $server]
expect "login:" { send "$user\r" }
sleep 5
expect "Password:" { send "$pass\r" }

expect {
"Last login" {
info_print " "
info_print "..Connected ! "
sleep 0.5
}
"Login failed" {
info_print "**FAILED** to TELNET to $server using ($user,$pass) "
exit
}
}

info_print "sudo $params"
send "sudo $params\r"
expect {
"Capturing" {
info_print "Starting capture .. "
expect {
"$user@" { info_print "Capture complete..! "}
}
}
}
}

run_remote localhost john john "/usr/sbin/tethereal -i ath0 -c 1 -w /tmp/sniff.capture"


All times are GMT -5. The time now is 10:41 PM.