Re: [Expect] Need to have explanations for the use of the expectcommand
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: [Expect] Need to have explanations for the use of the expectcommand

From: Andrew Falanga <not_real@hp.com>
Date: Fri Mar 17 2006 - 16:08:26 CET

Uwe Klein wrote:
> Hi,
>
> rewrite your script,
> see to it that you handle both
> success and failures:
>
> # change to fit:
> set user root
> set host testbox
> set passwd "!4you2know"
> set prompt "${host}:.*#"
> set errormessage "Login Failed"
> set successmessage "Hello $user, "
>
> # spawn a ssh session
> spawn ssh ${user}@$host
>
> # expect the password:
> expect \
> "word: " {
> puts stderr "password requested"
> exp_send $password\r
> } timeout {
> puts stderr "nobody at home"
> exit 1
> }
>
> # send passwd
> exp_send $password\r
>
> # expect OK/fail message
> expect \
> "$errormessage" {
> puts stderr "login failed"
> exit 2
> } "$successmessage" {
> puts stderr "login OK, waiting for prompt
> # continue this expect to wait for the prompt
> exp_continue
> } "$prompt" {
> puts stderr "prompt seen"
> } timeout {
> puts stderr "gone away?"
> exit 3
> }
>
>
> exp_send $my_restart_cmd_string
>
> expect ....
>
>
>
>
> uwe

Ok, thanks everyone for the help.

-- 
---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled.  I do not wish my account at HP to
become a spam haven.
Received on Sun Apr 30 02:37:57 2006