Question regarding expect and ssh
Brian Crabtree
briancrabtree1@gmail.com
Sat Mar 17 22:32:00 GMT 2012
Been trying to get a password reset script working with expect and ran
across a problem if I have a $ in the entered password it wraps the
variable in {}'s. Not sure if I'm missing an option somewhere or
doing something wrong. Newest version of cygwin available. I have
tried wrapping with "'s and using \$ and \\$ and neither made a
difference. I have confirmed that it is passing "{password1$}" as a
full string as my password was changed to that with my initial
testing.
Thanks,
Brian
$ ./passexpect_reset.sh ipaddress username password1$ password2
spawn ssh -l username ipaddress -o StrictHostKeyChecking=no
{password1$} password2
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {6516}
==============================
======
passexpect_reset.sh:
#!/usr/bin/expect -f
exp_internal 1
set ipaddr [lrange $argv 0 0]
set username [lrange $argv 1 1]
set oldpassword [lrange $argv 2 2]
set newpassword [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh -l $username $ipaddr -o StrictHostKeyChecking=no
$oldpassword $newpassword
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
send -- "$oldpassword\r"
# Look for shell
expect "*$username*"
send -- "passwd\r"
# Look for passwod prompt
expect "*?assword:*"
send -- "$oldpassword\r"
# Look for passwod prompt
expect "*?assword:*"
send -- "$newpassword\r"
# Look for passwod prompt
expect "*?assword:*"
send -- "$newpassword\r"
# send blank line (\r) to make sure we get back to gui
send -- "exit\r"
expect eof
====================================
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list