in reply to Strange behaviour with SSH command launched with open
It would take care of the low level details and can retry failed commands automatically.