Capturing SSH output
On the one hand, you need to capture the ssh output/error and store it into a file so that you can process it afterwards with Python. To this purpose you can:
1- Store output and error directly into a file
ssh user@node cmd 2>&1 > session.log
2- Show output/error in the console while storing it into a file (I would recommend this one)
ssh user@node cmd 2>&1 | tee session.log
Check this for further information about the tee command.
Running commands in parallel
On the other hand, you want to run both commands in parallel and block the current bash process. You can achieve this by:
1- Blocking the current bash process until their childs are done.
cmd1 & ; cmd2 & ; wait
Check this for further information about the wait command.
2- Spawning the child processes and freeing the current bash process. Notice that the processes will be kept alive although the main process ends.
nohup cmd & ; nohup cmd &
The whole thing
I would recommend combining both approaches using tee (so you can still see the ssh outputs on your terminal) and blocking the current process until everything is done (so that when you kill the main process all the processes are killed too).
ssh user@node1 uptime 2>&1 | tee session1.log & ; ssh user@node2 uptime 2>&1 | tee session2.log & ; wait
&to run the first command in the background. You can't stop it withCtrl+Cthen, though.&&, the second command is run only if the first one succeeded). "Blocking each other" would mean that the program communicate somehow, maybe over a common semaphore. Of coursessh user@node1 uptime & ssh user@node2 uptimewould run them in parralel, but I don't see much gain from it, since uptime is supposed to return quickly anyway.&instead of&&.