Linux Bash get IP address

Today I’ve tried to prepare auto configuration of my application and one of the main point was create correct cluster with real IP addresses . For example you have some config files where you want to put real IP of installed machine. In real Linux world it should be configured manually after installation but I want to emulate auto configuration, so, I’ve prepared bash script for auto config all parameters for my app, but one point was interesting and I’ve decided to describe it in a few words.

So, How to get real IP address ? Each of us know that there are ifconfig util and we can get all information about interfaces and addresses, I’ve used this for prepared short script to get real IP v4 address

ifconfig eth0  $1 | grep “inet addr” | awk -F: ‘{print $2}’ | awk ‘{print $1}’

Use it in your scripts if you want to do tasks as I had.

Thanks.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s