#!/usr/bin/expect -f # # Author(s) : Jean-Paul Saman # # Description: Start a connection and do some "useles" browsing and # other commands that can do no harm. # The actual purpose of this script is to keep the # connection open and active. Can be used for simulteneous # access tests. # # Arg1 : Hostname of IP address # Arg2 : Username # Arg3 : Password # # Return : 0 Everthing is oke, remote script executed properl # -1 Some scripting error occured, wrong arguments, etc # set Site [lindex $argv 0] set Port [lindex $argv 1] set User [lindex $argv 2] set Password [lindex $argv 3] # Open a connection on the remote machine... set timeout 30 spawn telnet $Site $Port expect { "Login:" { } "unknown" { send "quit\r" send_user "Error: login expected!\n" exit -1 } timeout { send "quit\r" send_user "Error: (timeout) login expected!\n" exit -1 } } # Sometime the telnet session hangs, probably due to # the fast inlogging (scripting), the following sleep # commands solve this hangup. sleep 1 send "$User\r" sleep 1 expect { "Password:" { } timeout { send "quit\r" send_user "Error: (timeout) Password expected!\n" exit -1 } } send "$Password\r" expect { "$User@vls>" { } "incorrect" { send_user "Error: remote user prompt expected!\n" exit -1 } timeout { send "quit\r" send_user "Error: (timeout) remote user prompt expected!\n" exit -1 } } # Do some commands, wait and do again for { set Index 10 } { $Index>0 } {} { send "echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ; date ; echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r" send "cd /bin\r" send "ls\r\r" sleep 5 expect { "$User@vls>" { } timeout { send_user "Error: (timeout) user prompt expected!\n" exit -1 } } incr Index -1 } # Close the connection... send "logout\r\r" expect { "Connection closed by foreign host" { } timeout { send_user "Error: connection closed expected!\n" exit -1 } } expect { "$User]" { } timeout { send_user "Error: local user prompt expected!\n" exit -1 } } # End script