Needed to move ssh outside main loop.

Some issue with the shell redirection confused the loop otherwise.