If you have a bash
script with a while
loop that reads from stdin
and uses ssh
inside that loop, the ssh
command will drain all remaining data from stdin
1. This means that only the first line of data will be processed.
I encountered this issue yesterday2. This website explains why the behavior occurs and how to avoid it.
A flawed method to run commands on multiple systems entails a shell while loop over hostnames, and a Secure Shell SSH connection to each system. However, the default standard input handling of ssh drains the remaining hosts from the while loop