3

I have issue with this code.

  while IFS='' read -r line
  do

    echo "host: "$line

    IP_addr=$(echo $line |cut -d" " -f1)
    host=$(echo $line | cut -d" " -f2)

    FILE_CHECK=$(ssh -o ConnectTimeout=10 $USER@$IP_addr "find $SRC_FILE -mtime 0")

    echo $FILE_CHECK

    ((host_num+=1))


    echo "" #empty line
  done < "$SERVER_LIST"

  echo $host_num

Where variable server list contain path to file with server

192.168.1.1 app1
192.168.1.2 app2
192.168.1.3 app3 

Script read first line, successfully connect to host and then exit. When I tried loop through file and only echo lines loop read all lines.

1
  • note you can say while read -r ip host to directly get the ip_addr and host instead of pulling those from $line. Commented Mar 27, 2018 at 9:05

1 Answer 1

4

ssh reads from stdin, so it will eat the rest of the file. Run ssh with the -n option to redirect its input to /dev/null.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.