expect and ssh

hello
I installed expect on my solaris box.

now I want to execute this command on several servers as root (all of them have the same root password):

for i in 1 2 3; do ssh root@"srv"$i" ls /; done;

I want of course to skip these 2 steps:

The authenticity of host 'srv3 (172.21.26.25)' can't be established.
RSA key fingerprint is 2f:0c:4a:ee:19:e1:7e:f2:c8:f6:ac:2a:44:58:be:7b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'srv3,172.21.26.25' (RSA) to the list of known hosts.
Password:

How to do that using expect??
thanks

Use the search function of the forum to select an example that will match your needs, there are lots of topics on that subject. Also, you can use "autoexpect" to achieve the same, look at its man pages.

#!/usr/bin/expect -f
spawn ssh -X root@<ip addr>
expect "password:"
sleep 1
send "password\r"
interact

I'd first suggest you set ssh keys for passwordless connections if possible. You don't want to write down your passwd in a text file.
For what you want to do, you can follow nitin09's suggestion, although I wouldn't use
-X (no need to forward X11), make sure to expect and answer the yes/no query, and make sure that the expected string matches the prompt's case, ie., Password. Otherwise you are going to spend 5-10 seconds waiting for the time out.

This will work properly only if you have never logged in as root and all of the servers reply the same thing, i.e., "The authenticity of host XXXXX can't be established". If you have logged in to some servers you will only get a password prompt. If that's the case, you will need to create an "if" statement within your expect script that will do one thing if you get one response and another if you get a different response.

Basically agreed. I've had to create a shared memory server and jump through hoops to deal with legacy services without *.equiv available in the past.

Expects RE engine is Tcl's so you can really match whatever regexp you need to get patterns within the expect body. exp_internal 1 is your friend and there are plenty of smart people out at comp.lang.tcl to help you if you run into problems that seem insuperable.