0

I have server list in file and in a while loop I will read and runt he command using ssh. it displays only last server uptime output. other servers its not displaying.

eg:

cat a
host1
host2

cat a | while read s; do ssh -q $s -x "uptime"; done

it shows only host2 uptime output.

we changed to run like this it displays both servers output

cat a | while read s; do echo "ssh -q $s -x uptime"|bash; done

I like to understand, why we need while read loop displaying only last output.

Is anyother way we can execute the ssh remote command using while loop?

Thanks SR

sfgroups
  • 16,514
  • 23
  • 105
  • 182

1 Answers1

0

You should do it like this:

while read -r s
 do ssh -q $s -x "uptime" </dev/null
done < a

This is happening because ssh is trying to read from stdin

arco444
  • 20,737
  • 10
  • 61
  • 64