• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:06
CET 22:06
KST 06:06
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview7RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress
Brood War
General
How Rain Became ProGamer in Just 3 Months BGH Auto Balance -> http://bghmmr.eu/ [BSL21] RO8 Bracket & Prediction Contest BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Fighting Spirit mining rates Current Meta
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1463 users

Shell Scripting Newb

Blogs > TheAmazombie
Post a Reply
TheAmazombie
Profile Blog Joined September 2010
United States3714 Posts
Last Edited: 2012-11-16 23:03:39
November 16 2012 21:55 GMT
#1
Well, so maybe not a total newb, but I haven't done it in a while. I used to do bash and zsh scripting a lot back when I had a use for it, but I have not even opened vi or emacs or whatever in at least 2 years. Mind you, I was never a pro at it, but I could get around well enough to write little automation scripts to make my job easier.

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.


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.


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!

*****
We think too much and feel too little. More than machinery, we need humanity. More than cleverness, we need kindness and gentleness. Without these qualities, life will be violent and all will be lost. -Charlie Chaplin
TheAmazombie
Profile Blog Joined September 2010
United States3714 Posts
November 16 2012 23:01 GMT
#2
LoL. Well, I got my cuts to work in formatting finally. I have always had issues with the cut output modifiers and arguments. I needed some help from one of my buddies how got me this:

nmap -sP 10.10.16.0/22 | grep fun | cut -d" " -f2,3 | tr -d "()"


That at least gives me the raw data that I need to work with, outputting this:

fun-test1.practice.com 10.10.16.148
fun-test2.practice.com 10.10.16.150
fun-test3.practice.com 10.10.16.158
fun-test4.practice.com 10.10.16.159
fun-test5.practice.com 10.10.16.162
fun-test6.practice.com 10.10.16.165
fun-test7.practice.com 10.10.16.166


Now I just need to do the comparison...
We think too much and feel too little. More than machinery, we need humanity. More than cleverness, we need kindness and gentleness. Without these qualities, life will be violent and all will be lost. -Charlie Chaplin
Please log in or register to reply.
Live Events Refresh
BSL 21
20:00
RO8 - Day 2
Tech vs Cross
Bonyth vs eOnzErG
ZZZero.O287
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 480
IndyStarCraft 172
JuggernautJason106
DisKSc2 32
UpATreeSC 17
StarCraft: Brood War
Britney 15990
Calm 2366
Shuttle 469
Mini 334
ZZZero.O 287
EffOrt 181
Dewaltoss 75
ggaemo 62
Dota 2
Gorgc5417
420jenkins222
LuMiX1
Counter-Strike
fl0m9737
byalli549
Super Smash Bros
hungrybox130
Heroes of the Storm
Khaldor533
Liquid`Hasu484
Other Games
Grubby4342
B2W.Neo544
ArmadaUGS155
Fuzer 81
OptimusSC21
Organizations
Other Games
gamesdonequick1521
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• HeavenSC 44
• sitaska23
• Adnapsc2 20
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Airneanach27
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV506
Other Games
• imaqtpie2468
• Shiphtur575
Upcoming Events
Replay Cast
11h 54m
Wardi Open
14h 54m
Monday Night Weeklies
19h 54m
Sparkling Tuna Cup
1d 12h
OSC
2 days
YoungYakov vs Mixu
ForJumy vs TBD
Percival vs TBD
Shameless vs TBD
Replay Cast
3 days
The PondCast
3 days
OSC
4 days
CranKy Ducklings
5 days
SC Evo League
5 days
[ Show More ]
BSL 21
5 days
Sparkling Tuna Cup
6 days
BSL 21
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

CSL 2025 WINTER (S19)
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.