I have a file containing list of servers:
server1.me.com
server2.me.com
server3.me.com
And this is my bash file:
#!/usr/bin/bash
while read -r line
do
ssh -np2222 -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$line"
'mkdir -pv /root/newimages/'
rsync -Ptrave 'ssh -p2222' /root/*.tar "$line":/root/newimages/
ssh -np2222 -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$line"
'find /root/newimages/ -name "*.tar" -exec docker load -i {} ;'
done < servers.txt
In a normal run, it runs line by line, which takes a lot of time.
How can I run it in a less time, so that let’s say 5 lines run at the same time instead of 1 line?
I mean, at the same time it should create an SSH connection to server1
, server2
, server3
, server4
and server5
at the same time.
I don’t know what words to google, if it’s been asked before.