I have a script that runs remote commands on several different machines via an ssh connection. The script looks something like this:
for server in list; do
echo "output from $server"
ssh to server execute some command
done
The problem with this, obviously, is time, since it needs to establish an ssh connection, a fire brigade command, wait for a response, print it. I would like the script to try to establish connections immediately and return echo "output from $ server" and output the command immediately after receiving it, therefore it is not necessary in the order of the list.
I searched for this for a while, but could not find an answer. I cannot cancel the ssh session after running the command as a single thread, because I need the output, and I cannot use the parallel gnu suggested in other threads. Also, I cannot use any other tool, I cannot bring / install anything on this computer, only a useful tool is GNU bash, version 4.1.2 (1) -release.
Another question: how limited are ssh sessions? If I just insert 5 or more lines of "ssh connect, do some command", it actually does nothing or will execute only the first one from the list. (it works if I insert 3-4 rows). Thanks you
source
share