I have to login into various servers using ssh parallely using a shell script. It is a password less authentication. I have to login into 25 servers and restart a process which takes a lot of time. Hence i want to do the process in all the servers at the same time. My script goes like this:
while read line
do
ssh $line
------restart process-------
done < list.txt &
Here "list.txt" has the list of servers. I have used "&" to invoke new shell for each iteration and repeat the process for all servers. But the script is still executing the restart process for the servers in the list one after other. Its not executing the restart process at the same time. the server where script runs is bulit on bash whereas the 25 servers where the process has to be restarted are bulit on korn shell. Can anyone tell me what is the mistake in the script or parallel login using ssh is possible or not? Thanks in advance
Untested, but this should work using a heredoc
- see Wikipedia heredoc:
while read line
do
ssh $line <<'EOF' &
command
command
EOF
done < list.txt
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments