Skip to content

Instantly share code, notes, and snippets.

@arttuladhar
Created July 10, 2013 15:16
Show Gist options
  • Save arttuladhar/5967168 to your computer and use it in GitHub Desktop.
Save arttuladhar/5967168 to your computer and use it in GitHub Desktop.
Expect Script to run command on remote server
#!/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