Created
July 10, 2013 15:16
-
-
Save arttuladhar/5967168 to your computer and use it in GitHub Desktop.
Expect Script to run command on remote server
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 | |
#Expect Script to Run Command on Remote Server | |
#Usage : ./test.sh <password> <servername> <username> | |
#Usage : ./test.sh password myserver user | |
#Set your command you want to run | |
set command "cat /etc/hosts | grep -i" | |
set pass [lrange $argv 0 0] | |
set server [lrange $argv 1 1] | |
set name [lrange $argv 2 2] | |
set timeout 2 | |
spawn ssh $name@$server $command $server | |
expect "RSA key fingerprint" { send "yes\r" } | |
expect "?assword:*" { send "$pass\r" } | |
send -- "\r" | |
interact |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment