• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 23:11
CEST 05:11
KST 12:11
  • 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
TL.net Map Contest #21: Voting3[ASL20] Ro4 Preview: Descent7Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 6-12): Four star herO65.0.15 Patch Balance Hotfix (2025-10-8)71Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition325.0.15 Balance Patch Notes (Live version)119
StarCraft 2
General
Ladder Impersonation (only maybe) 5.0.15 Patch Balance Hotfix (2025-10-8) The New Patch Killed Mech! TL.net Map Contest #21: Voting Weekly Cups (Oct 6-12): Four star herO
Tourneys
Master Swan Open (Global Bronze-Master 2) Tenacious Turtle Tussle WardiTV Mondays SC2's Safe House 2 - October 18 & 19 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
BW General Discussion [ASL20] Ro4 Preview: Descent BSL Season 21 BW caster Sayle ASL20 General Discussion
Tourneys
[ASL20] Semifinal B [ASL20] Semifinal A [Megathread] Daily Proleagues [ASL20] Ro8 Day 4
Strategy
Current Meta BW - ajfirecracker Strategy & Training Siegecraft - a new perspective TvZ Theorycraft - Improving on State of the Art
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Inbreeding: Why Do We Do It…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1319 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
PiGosaur Monday
00:00
#53
PiGStarcraft578
SteadfastSC160
EnkiAlexander 69
rockletztv 35
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft578
WinterStarcraft526
SteadfastSC 148
RuFF_SC2 91
CosmosSc2 87
Nathanias 66
Nina 4
StarCraft: Brood War
Larva 795
Icarus 6
Dota 2
monkeys_forever372
League of Legends
JimRising 700
Reynor41
Counter-Strike
Stewie2K333
Other Games
summit1g8084
C9.Mang0483
Skadoodle323
ViBE195
Maynarde145
fpsfer 4
Organizations
Other Games
gamesdonequick6445
Counter-Strike
PGL3019
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH119
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt434
Other Games
• Scarra858
Upcoming Events
OSC
19h 49m
The PondCast
1d 6h
OSC
1d 8h
Wardi Open
2 days
CranKy Ducklings
3 days
Safe House 2
3 days
Sparkling Tuna Cup
4 days
Safe House 2
4 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 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
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 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.