So today I started writing a new little script to automate one of my normal everyday functions, but I am having issues with how to construct it here. I was able to pull some info from google and my old scripts, but after much digging it appears that only a few of my old ones still exist. Most seem to have been lost. Google, when it comes to code, it not always the best though because it will sometimes give you similar examples, but most of the time nothing exactly like what you need or you get a ton of random things, some might work, others not.
I am using an nmap -sP sweep ping to sort through IPs on certain subnets. That is the easy part. I also have a nice, clean menu system in place (via and until, do, and case function), but really where I am getting lost again is in parsing and formatting.
I am going to give an example of what I am getting. Mind you, IPs and Hostnames are different as to not give out some of that personal info. Anyway, here is my example command:
nmap -sP 10.10.16.0/22 | grep fun
...then my results return:
Host fun-test1.practice.com (10.10.16.148) appears to be up.
Host fun-test2.practice.com (10.10.16.150) appears to be up.
Host fun-test3.practice.com (10.10.16.158) appears to be up.
Host fun-test4.practice.com (10.10.16.159) appears to be up.
Host fun-test5.practice.com (10.10.16.162) appears to be up.
Host fun-test6.practice.com (10.10.16.165) appears to be up.
Host fun-test7.practice.com (10.10.16.166) appears to be up.
Host fun-test8.practice.com (10.10.16.167) appears to be up.
Host fun-test9.practice.com (10.10.16.169) appears to be up.
Host fun-test2.practice.com (10.10.16.150) appears to be up.
Host fun-test3.practice.com (10.10.16.158) appears to be up.
Host fun-test4.practice.com (10.10.16.159) appears to be up.
Host fun-test5.practice.com (10.10.16.162) appears to be up.
Host fun-test6.practice.com (10.10.16.165) appears to be up.
Host fun-test7.practice.com (10.10.16.166) appears to be up.
Host fun-test8.practice.com (10.10.16.167) appears to be up.
Host fun-test9.practice.com (10.10.16.169) appears to be up.
Of course I get all host info from my sweep ping on the .16.0 network segment which begin with the word "fun." This is what I want. Now, here is where I can't seem remember how to go about doing and I am hoping that TL scripters can give me a nudge in the right direction...
What I want is to compare this info to a pre-set list of hostnames and IPs, use that info to compile a new list of all hosts that are NOT up, then return that info in something similar to:
Host fun-test10.practice.com (10.10.16.14) appears to be available.
Host fun-test20.practice.com (10.10.16.50) appears to be available.
Host fun-test30.practice.com (10.10.16.58) appears to be available.
Host fun-test40.practice.com (10.10.16.59) appears to be available.
Host fun-test50.practice.com (10.10.16.62) appears to be available.
Host fun-test60.practice.com (10.10.16.15) appears to be available.
Host fun-test70.practice.com (10.10.16.16) appears to be available.
Host fun-test80.practice.com (10.10.16.17) appears to be available.
Host fun-test90.practice.com (10.10.16.19) appears to be availabe.
Host fun-test20.practice.com (10.10.16.50) appears to be available.
Host fun-test30.practice.com (10.10.16.58) appears to be available.
Host fun-test40.practice.com (10.10.16.59) appears to be available.
Host fun-test50.practice.com (10.10.16.62) appears to be available.
Host fun-test60.practice.com (10.10.16.15) appears to be available.
Host fun-test70.practice.com (10.10.16.16) appears to be available.
Host fun-test80.practice.com (10.10.16.17) appears to be available.
Host fun-test90.practice.com (10.10.16.19) appears to be availabe.
Now, it dawns on me that I don't have the slightest recollection on how to do that...if I could just get a tiny push in the right direction, it might be helpful. Or hell, just tell me this is a stupid idea for a script and to just give up...that might help. Haha.
I know that I used to do thins kind of thing with a "for each do" type of statement, but those were always inclusive, not exclusive...so now I am lost.
Damn you linux! Why do I torture myself, slaving away at you, all day long!