• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:06
CEST 17:06
KST 00: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
Serral wins EWC 202543Tournament Spotlight: FEL Cracow 202510Power Rank - Esports World Cup 202580RSL Season 1 - Final Week9[ASL19] Finals Recap: Standing Tall15
Community News
Weekly Cups (Jul 28-Aug 3): herO doubles up6LiuLi Cup - August 2025 Tournaments3[BSL 2025] H2 - Team Wars, Weeklies & SB Ladder10EWC 2025 - Replay Pack4Google Play ASL (Season 20) Announced58
StarCraft 2
General
Weekly Cups (Jul 28-Aug 3): herO doubles up Clem Interview: "PvT is a bit insane right now" Serral wins EWC 2025 TL Team Map Contest #5: Presented by Monster Energy Would you prefer the game to be balanced around top-tier pro level or average pro level?
Tourneys
Global Tourney for College Students in September Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays $5,000 WardiTV Summer Championship 2025 LiuLi Cup - August 2025 Tournaments
Strategy
Custom Maps
External Content
Mutation # 485 Death from Below Mutation # 484 Magnetic Pull Mutation #239 Bad Weather Mutation # 483 Kill Bot Wars
Brood War
General
BW General Discussion Help, I can't log into staredit.net How do the new Battle.net ranks translate? Which top zerg/toss will fail in qualifiers? Google Play ASL (Season 20) Announced
Tourneys
[CSLPRO] It's CSLAN Season! - Last Chance [Megathread] Daily Proleagues [ASL20] Online Qualifiers Day 2 Cosmonarchy Pro Showmatches
Strategy
Simple Questions, Simple Answers [G] Mineral Boosting Muta micro map competition Does 1 second matter in StarCraft?
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Total Annihilation Server - TAForever Beyond All Reason [MMORPG] Tree of Savior (Successor of Ragnarok)
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
European Politico-economics QA Mega-thread US Politics Mega-thread Things Aren’t Peaceful in Palestine Bitcoin discussion thread 9/11 Anniversary
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment" Computer Build, Upgrade & Buying Resource Thread
TL Community
TeamLiquid Team Shirt On Sale The Automated Ban List
Blogs
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
The Link Between Fitness and…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
Customize Sidebar...

Website Feedback

Closed Threads



Active: 840 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
Stormgate Nexus
14:00
Stormgate Launch Days
BeoMulf221
TKL 194
IndyStarCraft 179
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Reynor 360
SpeCial 81
StarCraft: Brood War
Britney 50665
Bisu 3971
Shuttle 2425
Mini 930
Soulkey 575
ggaemo 463
Snow 365
actioN 350
ZerO 277
Soma 221
[ Show more ]
Hyuk 197
sSak 157
Leta 91
ToSsGirL 76
sorry 74
Nal_rA 57
Sharp 56
Aegong 40
soO 39
[sc1f]eonzerg 33
sas.Sziky 29
zelot 27
scan(afreeca) 20
Rock 17
ajuk12(nOOB) 17
Sacsri 16
Terrorterran 13
Backho 12
IntoTheRainbow 10
SilentControl 9
JulyZerg 8
ivOry 4
Stormgate
BeoMulf221
TKL 194
IndyStarCraft 179
Dota 2
Gorgc5777
Dendi1606
XcaliburYe381
Counter-Strike
pashabiceps504
flusha368
byalli292
kRYSTAL_56
Heroes of the Storm
XaKoH 112
Other Games
gofns1900
hiko891
Beastyqt480
crisheroes383
KnowMe370
Hui .365
RotterdaM261
DeMusliM253
Fuzer 212
ArmadaUGS92
QueenE71
ZerO(Twitch)18
Trikslyr14
Organizations
StarCraft 2
WardiTV1060
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 84
• poizon28 23
• davetesta16
• Kozan
• AfreecaTV YouTube
• intothetv
• sooper7s
• IndyKCrew
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• FirePhoenix10
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV791
League of Legends
• Nemesis2797
• Jankos1054
Upcoming Events
uThermal 2v2 Circuit
54m
DaveTesta Events
8h 54m
The PondCast
18h 54m
WardiTV Summer Champion…
19h 54m
Replay Cast
1d 8h
LiuLi Cup
1d 19h
uThermal 2v2 Circuit
1d 23h
RSL Revival
2 days
RSL Revival
2 days
uThermal 2v2 Circuit
2 days
[ Show More ]
CSO Cup
3 days
Sparkling Tuna Cup
3 days
uThermal 2v2 Circuit
3 days
Wardi Open
4 days
RotterdaM Event
5 days
RSL Revival
6 days
Liquipedia Results

Completed

ASL Season 20: Qualifier #2
FEL Cracow 2025
CC Div. A S7

Ongoing

Copa Latinoamericana 4
Jiahua Invitational
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
HCC Europe
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025

Upcoming

ASL Season 20
CSLPRO Chat StarLAN 3
BSL Season 21
BSL 21 Team A
RSL Revival: Season 2
Maestros of the Game
SEL Season 2 Championship
WardiTV Summer 2025
uThermal 2v2 Main Event
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 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.