Im trying to develop a script that finds a specific pattern in the output of the dig command running against a list of domains. To do this I'm using grep but having difficulty implementing this using multiple logical operations.
I want to achieve something like this:
if output contains ("NXDOMAIN") and ("test1.com" or "test2.com"); then echo output;
I have managed to get it working for the pattern
"NXDOMAIN" by piping the output into grep but I am lost on how to implement the logical operators. My script so far:
#!/bin/bash input="/root/subdomains.txt" while IFS= read -r line do output=$(dig "$line") if echo "$output" | grep "NXDOMAIN" >&/dev/null; then echo "$output"; else echo " " >&/dev/null; fi done < "$input"
Is using grep the best way to achieve this?