How about this, from a bash prompt:
cat filewithIPs | while read host
do
ssh root@$host <command>
sleep 10
done
That will process each host/IP one at a time from the prompt, doing whatever it is you need to do to each host with ssh.
Printable View
The problem with using 'shell' – ie bash to connect to a remote server is that it can not return back to the shell. So the example that Ped gave you wont work because the remote host is waiting for a return (\r) character or a line feed (\n) character. The concept is perfect but it will not work using shell.
There are a number of ways of dong this. PERL is one way but its quite a task to 'interact'. The very best way which is easy to understand is tcl/expect. This was written by a guy called Don Libes for exactly the same type of task that you want to achieve – ie where you need to interact.
If you are able to install 'tcl/expect 'on your system and you want to use this approach, then I can give you the information/examples that will perform your tasks.
I think mine may work, with a slight modification.
cat filewithIPs | while read host
do
ssh root@$host <<-EOF
commands to execute on remote host go here...
exit
EOF
sleep 10
done
In fact, I just tested it locally on my system and it worked.
You might want to look at "clusterssh" see SourceForge.net: clusterssh
Thanks, Nick... :-)
#/bin/sh
declare the variables for your task
like:
HOST_FILE=<path to the host file>
for H in $(cat $HOST_FILE)
do
ping -c1 -t1 $H 2>&!
TEST=$?
if [ $TEST = 0 ]; then
ssh $H "execute teh command to perform your task"
fi
done