[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2012-12-26
4
Medium Priority
?
361 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Fine Tune your automatic Updates for Ubuntu / Debian
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 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