0

I have a file listing 1 or more server's hostnames hostname_list that I generate using grep and awk. Now I need to execute salt commands against the hostnames. I am trying, as a test, to run test.ping to ping each server in the list.

I have tried doing it as a for loop but I can't get it to work.

I've tried numerous variations of:

for i in hostname_list
do 
    salt $i test.ping
done
pretz
  • 161

1 Answers1

3

Under assumption that hostname_list is a text file containing 1 hostname per line, you can use this:

while read -r line
do
    [[ -n "$line" ]] && salt $line test.ping
done < hostname_list

The [[ -n "$line" ]] statement checks that the line is not empty before executing the following command.