Skip to content

Instantly share code, notes, and snippets.

@91xcode
Forked from oxyc/ssh.exp
Created June 9, 2017 03:23
Show Gist options
  • Save 91xcode/2d6886d248a5b2393103dcc829a98bba to your computer and use it in GitHub Desktop.
Save 91xcode/2d6886d248a5b2393103dcc829a98bba 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