-
-
Save 91xcode/2d6886d248a5b2393103dcc829a98bba 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