Solved

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

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

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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 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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

775 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