Skip to content

Instantly share code, notes, and snippets.

@dahernan
Created March 28, 2011 16:02
Show Gist options
  • Save dahernan/890721 to your computer and use it in GitHub Desktop.
Save dahernan/890721 to your computer and use it in GitHub Desktop.
Exec ssh command passing the password as a parameter
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 c3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh root@$ipaddr $scriptname $arg1
match_max 100000
expect -timeout 4 "yes/no" {send "yes\r"}
# Look for passwod prompt
expect "password:" {send -- "$password\r"}
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment