Solved

A little bash script to give me just the ip's for a system

Posted on 2012-12-26
4
351 Views
Last Modified: 2012-12-28
I need a little bash script to give me just the ip addresses on a system

there are 2 catches

Catch # 1, I need them all in one line:

10.10.10.10 10.10.10.11 10.10.10.12

Note the above is 3 ip addresses on one line

the second catch ( and the harder one)  I need 1 script for each of:
redhat linux, Solaris, AIX

I am making a report on boxes for the IP's used

thx
0
Comment
Question by:TIMFOX123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38721404
ifconfig -a | grep -w inet |awk '{gsub("addr:",""); printf $2 " "} END {print " "}'

To filter out "127.0.0.1" ("loopback"/"localhost"):

ifconfig -a | grep -w inet |awk '{gsub("addr:",""); if($2!~"127.0.0.1") printf $2 " "} END {print " "}'

Should do on Solaris, AIX and Linux (I don't have a RH system here, just SuSe etc., hope it works anyway).

To display inet6 addresses use "grep -w -inet6" instead of "grep -w inet", and to mix both address types in the output use "grep inet".
0
 

Author Comment

by:TIMFOX123
ID: 38721905
great job however one little problem

in solaris I get ( awk error )

worked great on linux and aix :)

can you take a shot at solaris 10 :)
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38721949
OK,

under Solaris try "nawk" instead of "awk"!

AIX has "nawk" too, but I fear Linux hasn't (at least the ones I have access to).

So we might have to add a check for uname, or we could link nawk to awk on Linux.
0
 

Author Closing Comment

by:TIMFOX123
ID: 38727140
this did the job very very well
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question