Regex match in shell script
I'm writing a shell script that makes sure my DNS server is looking. Here's the output it tests:
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: galapagos.office
Address: 192.168.140.25
Everything but the "galapagos.office" needs to match exactly. The "galapagos.office" part itself doesn't actually matter at all.
I figure I can apply this regex to the output to tell me if it开发者_JS百科 looks how I want:
Server: +127\.0\.0\.1\nAddress: +127\.0\.0\.1#53\n\nName:.+\nAddress: 192\.168\.140\.25
The thing is I don't really know shell scripting. What's the best way to make sure that regex matches the output of an nslookup command?
Just a guess of what you actually want
awk '/Server/&&$2=="127.0.0.1"{f=1}
/Address/&&$2=="127.0.0.1#53"{g=1}
/Address/&&$2=="192.168.140.25"{h=1}
END{if(h && g && f) print "ok"}' file
精彩评论