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

TIMFOX123
TIMFOX123 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013

Commented:
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".

Author

Commented:
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 :)
Most Valuable Expert 2013
Top Expert 2013
Commented:
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.

Author

Commented:
this did the job very very well

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial