public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Question regarding expect and ssh
@ 2012-03-17 22:32 Brian Crabtree
  0 siblings, 0 replies; only message in thread
From: Brian Crabtree @ 2012-03-17 22:32 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-03-17 22:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-17 22:32 Question regarding expect and ssh Brian Crabtree

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).