Skip to content

Instantly share code, notes, and snippets.

@oxyc
Created February 23, 2012 06:23
Show Gist options
  • Save oxyc/1891065 to your computer and use it in GitHub Desktop.
Save oxyc/1891065 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect -f
# Usage:
# ./ssh.exp USER PASS IDENTITY_FILE HOST COMMAND
set username [lrange $argv 0 0]
set password [lrange $argv 1 1]
set identity_file [lrange $argv 2 2]
set host [lrange $argv 3 3]
set command [lrange $argv 4 4]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh -l $username -i $identity_file $host $command
match_max 100000
# Look for passwod prompt
expect "*?assphrase*"
# Send password aka $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