Why does SSH break out of the while loop?
Commenting out the ssh-command makes the loop work as it should. Does anybody know why this happens and how one can prevent ssh from breaking the while-loop? The problem is that ssh reads from standard input, therefore it eats all your remaining lines. You can just connect its standard input to nowhere:
How to make SSH not read from standard input?
A little more direct is to use the -n flag, which tells ssh not to read from standard input. It’s not parallel ssh but it works. I open-sourced a command line tool called Overcast to make this sort of thing easier.
How to SSH in a list of servers?
I have a text file in which I have a list of servers. I’m trying to read the server one by one from the file, SSH in the server and execute ls to see the directory contents.
How to stop SSH from reading from stdin?
The problem with this code is that ssh starts reading data from stdin, which you intended for read line. You can tell ssh to read from something else instead, like /dev/null, to avoid eating all the other hostnames. A little more direct is to use the -n flag, which tells ssh not to read from standard input.
Why do I only see the first line in do _ work.sh?
In do_work.sh, I run a couple of ssh commands. The problem is that do_work.sh runs ssh commands and by default ssh reads from stdin which is your input file. As a result, you only see the first line processed, because ssh consumes the rest of the file and your while loop terminates.
How to prevent ssh from reading from stdin?
To prevent this, pass the -n option to your ssh command to make it read from /dev/null instead of stdin. More generally, a workaround which isn’t specific to ssh is to redirect standard input for any command which might otherwise consume the while loop’s input.
What to use instead of redirection in SSH?
You can just connect its standard input to nowhere: You can also use ssh -n instead of the redirection.