The most basic check to see if a file contains a particular pattern is with the common grep
command-line utility.
With the correct flags and options you can build a basic script that does something along the lines of the following pseudo-code:
# Break down the elements you're looking for
# in basic regular expression patterns
# and store them in an array
MyRequiredEntries=("nameserver\s*1.1.2.2" "nameserver\s*3.3.4.4" "domain\s*example.com" "search\s.*abc\.com" "search\s.*abc\.net")
# Loop over the array elements
for MyEntry in "${MyRequiredEntries[@]}"
do
# use the exit code of grep -q for further logic
grep -q "$MyEntry" /etc/resolv.conf
MyResult=$?
if [ $MyResult -eq 0 ] ; then
echo "do something when resolv.conf contains the pattern $MyEntry"
else
echo "do something when resolv.conf does NOT contain the pattern $MyEntry"
fi
done
Which can of course be fine-tuned according to your needs.
As others have commented: rather than doing a game of "spot the differences" you may want to step back and think as to why you're running this test and what you intend to do with your findings.
If the end result is to ensure that all servers have the correct configuration, then preferably start managing them with a configuration management system and avoid these differences from occurring in the future.
And if starting a central configuration management solution is still a bridge too far, rather than testing and then manually fixing settings: don't bother and directly apply the correct settings everywhere...
One a side-note: when (some of) your systems are configured with DHCP, you may want to start with pushing the correct settings from there.