Running a script on multiple remote hosts at once

I have a script on about 15 hosts that I need to run for each host whenever I want (not crontab). Problem is, this script takes 5-10 mins to run for each host. Is there a way I can run the script in parallel for all the hosts instead of 1 at a time? Also, I'm remotely running the script on the hosts from my home host, using remsh.

Apologies if this is an ignorant response, but can you not just kick them off in the background (Assuming you use a key exchange or a hosts file)?

for i in $(cat hosts.txt); do ssh user@${i} '/usr/local/scripts/test.sh' &; done

If you can't do the above, you should be able to just use expect to loop through them, assuming you need to login. You can spawn multiple rsh sessions and perform operations in parallel like that.

1 Like

Useless Use of Cat

while read LINE
do
        command &
done < inputfile

wait

thanks