View Single Post
  #8   (View Single Post)  
Old 3rd February 2011
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 192
Default

@isthistheend

I was pretty sure my message came before yours yesterday...

Anyway, I just redesigned awk script a bit to add "no IP" output and a few comments:

Code:
# First we skip interfaces we don't want shown
# Comment out if want to display them too

/lo0/||/enc/{next}

# We remember interfaces in iface variable, and increase gotif
# If we get more that 2 interfaces it means last one doesn't have an address
# so we put it in noip array and decrease the gotif counter

/flags/{
	if(++gotif>1){noip[iface]++; gotif--}

	iface=$1
}

# We found an address. We put interface and address in buf array
# and decrease counter by 1

/inet /&&gotif{	
	buf[iface]=$2
	gotif--
}
# END block
END{	

	# If we still have counter set it means there is last interface
	# that doesn't have an address so we include that one too

	if(gotif>=1) noip[iface]++

	# We print out both arrays

	for(i in buf) printf("%s\t%s\n", i, buf[i])
	for(j in noip) printf("%s\tNo address\n", j)
}
Try to call it as:
Code:
ifconfig -a | awk -f thascript.awk
I leave to you to get "status" message displayed in output, just make sure you post it here in case someone else needs it as well.

All best
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD
Reply With Quote