Unexpected result in while do done loop reading file
I have this while do done loop in a bash shell script:
while read line;
ssh root@anotherserver "hostname"
It reads the first line of /tmp/get_mbx_stats.tmp OK, and I get the correct results from the ssh and the echo commands, but then it drops out of the loop, even though there are many more lines in /tmp/get_mbx_stats.tmp.
If I comment out the ssh command, it works as expected - it reads and echoes all the lines in the input file.
I have tried many variations but they always fail with the same issue.
(Actually I need to get information from "anotherserver" - not simply its hostname - but I boiled it down to the simplest ssh I could think of).
Is the ssh command changing the file status in some way?
Thanks in advance...
This is a known issue with ssh trying to read from standard input and sending a SIGTTIN signal to the parent shell upon exit. You can try the option -n of ssh, that circumvent this problem, redirecting standard input from /dev/null or explicitly redirect standard input in the ssh command line:
Thank you!!! I used the -n option, and that fixed the problem!!
|All times are GMT -5. The time now is 06:35 PM.|