I have a text file which lists a hostname and in the line directly under states the results of a ping of a salt minion. Here is an example output:
T5F6Z12: Minion did not return. [Not connected]
I need to be able to first identify is the text (Minion did not return) exists and if so grab the hostname associated with the error so I can run other commands against that server.
I have started with this:
if grep -q "Minion" /srv/salt/test/ping_results then
So I'm pretty sure I need to grep for the word "Minion" because it will only show up for servers that failed the test. But once I've identified it exists, I'm not sure how to grab the associated hostname above it in the text file.