Created
February 23, 2012 06:23
-
-
Save oxyc/1891065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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