Solved

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

Posted on 2012-12-26
4
309 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now