Hi.

Your script may not work correctly if the password begins
with "-".  The following script comes from my own book
(except English comment) :-P

---- 8X ---- 8X ---- 8X ---- 8X ---- 8X ---- 8X ----
#!/usr/bin/expect -f
set username [lindex $argv 0]
set password [lindex $argv 1]

spawn passwd $username

expect {
    "\[Pp\]assword*:" {
        sleep 1
        send -- "$password\r"
        exp_continue
    }
    timeout {
        send_error "Unexpected response/No response from passwd.\n"
        exit 2
    }
    eof {
        # check status code
        set status [lindex [wait] 3]
        if {$status > 0} {
            # print unprocessed error
            send_error "$expect_out(buffer)"
            exit $status
        }
    }
}
---- X8 ---- X8 ---- X8 ---- X8 ---- X8 ---- X8 ----

From: [EMAIL PROTECTED]
Date: Tue, 10 May 2005 13:53:20 +0930

> 10May2005 @ 12:30 [EMAIL PROTECTED] thusly spake
> > I have the following 'Expect' script:
> > 
> > ~_________ doPass ________________________ 
> > /
> > #!/usr/bin/expect -f
> > set username [lindex $argv 0]
> > set password [lindex $argv 1]
> > 
> > spawn passwd $username
> > expect "New password: " 
> sleep 2
> > send "$password\r"
> > expect "Retype new password: "
> sleep 2
> > send "$password\r"
> > send "exit\r"
> > expect eof
> > \_________________________________________
> > 
> > This works fine the first time, then times out when running consecutive 
> > times.
> > Does anyone know what is happening and why it times out if I run it twice 
> > or 3
> > times in a row?
> 
> Thanks for your help. As usual I found out what it was soon after I posted.
> See the additions to the above script. It becomes obvious when you think about
> it.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to