Q:

Loop broken by ssh running script aside

I have a couple of machines to update some script on. I can do this with a small bash script on my side, which consists of one while loop for reading IPs from a list and calling scp for them. It works fine, but when I try to run updated script in a loop, it break the loop, although runs quite fine itself.
#!/bin/bash

cat ip_list.txt | while read i; do
    echo ${i}
    scp the_script root@${i}:/usr/sbin/ # works ok
    ssh root@${i} /usr/sbin/the_script  # works for a first IP, then breaks
done

Is this how it suppose to work? If so, how can I run a script remotely via ssh without breaking the loop?

A:

Use this:
ssh -n root@${i} /usr/sbin/the_script  # works for a first IP, then breaks

The -n option tells ssh not to read from stdin. Otherwise, it reads stdin and passes it through to the network connection, and this consumes the rest of the input pipe.

