bash, ssh and expect to multiple ip addresses

Hi, I need script that will allow me to connect to multiple clients using ssh on Ubuntu terminal...
I have a txt file with the ip addresses of clients, i need a script that will connect to everyone one by one and send some commands...
The idea is to check some settings on every client automatically.
They all have same UN and PASS but i can't use public key so I need to use expect probably... Can someone, please, post example how to do that?
Thnx a lot and sorry for any mistakes, my English is not so good.

Try this...

#!/bin/sh

stty -echo;
read -p "Input password:" A;
stty echo;
echo;
ip_address_list=/tmp/ip_address_list.txt

for HOST in `cat $ip_address_list`
do
echo "Connecting to $HOST"
expect -c "set timeout -1;\
spawn ssh $HOST -l root \"whoami;id;pwd\";\ #you can type any commands you want...
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;"
echo "Finished job on $HOST"

done

1 Like

thank you very much :slight_smile:
I'll try it later, hope it's gonna work...

once again tnx man...