0

I am trying to retrieve a string of text from a file which exists on a bunch of remote servers. The servers all have a custom port number so I put those numbers in a file called "port_numbers.txt" (one on each line). I want to repeat this command using the output of the text file line by line until the end of the file.

I hope to end up with a script that will give me the string I need for every server on my list. So far, the script stops after the first line. What is the best way to repeat the command but each time, the next line is used to replace the "$line" value?

#!/bin/bash

filename="port_numbers.txt"

while IFS= read -r line do ssh host -p"$line" "grep -Ei 'STRING' /path/to/file" done

Output:

sh myscript.sh
user@hostname's password:
  "STRING":"STRING: STRING",

0 Answers0