I am trying to get the output of hostnames based on OS type (want only RedHat server hostnames) set as a variable.
but my code keeps spitting out the string RedHat along with each hostname.
minions=$(salt-run manage.up | cut -a " " -f2)
hosts=$(for minion in ${minions[@]}; do salt ${minion} grains.items | grep "os_family:" | grep RedHat && echo ${minion}; done)
CodePudding user response:
By default grep
will ouput the results of the pattern match.
If your version of grep
supports it ... the -q
flag will suppress the output:
... | grep -q RedHat && echo ${minion}; done)
Alternatively, redirect the output to /dev/null
:
... | grep RedHat >/dev/null && echo ${minion}; done)