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