0

This question already has an answer here:

For some reason, this script (run on RHEL v6.9) processes only the first line in the host_file

#!/bin/bash

process()
{
 ssh $host ls
}

while IFS= read -r host
do
  echo "Running $host"
  process
  echo "DONE $host"
done < host_file
#-------End of Script-----------------

$ cat host_file
server1
server2

marked as duplicate by Kusalananda bash Aug 31 '18 at 21:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

ssh will slurp up the rest of stdin. Use a different file descriptor for the while-read loop:

while IFS= read -u4 -r host
do
  echo "Running $host"
  process
  echo "DONE $host"
done 4< host_file

Not the answer you're looking for? Browse other questions tagged or ask your own question.