I'm trying to get Expect to execute commands on a remote server using SSH with username/password authentication
My current expect script is
Code:
#!/usr/bin/expect -f
spawn ssh -tq root@my_hostname "whoami"
match_max 10000
expect "*?word:*"
send -- "my_password\r"
send -- "\r"
expect eof
But this returns
Code:
spawn ssh root@my_hostname whoami
root@my_hostname's password:
root
But all I need is the last line, also I need the script to return the exit code of the command run.
I'm aware this is insecure.
I cannot use key based ssh authentication, the servers are Amazon EC2 servers that are never running for more than 12 hours so every time I start a new one it has a new hostname so the keys are invalid.
Bar that, is there a better solution to this problem?