scripts to quickly get IPs of network interfaces

Managing lots of servers and issuing the same commands over and over again can get boring really fast, so I wrote some scripts to quickly get private and public IPs and also IPs of other network interfaces I might have.

getip.sh:

#!/bin/bash

intf=$1

if [[ -n "$intf" ]]; then  
  ifconfig $intf | grep "inet addr" | cut -d: -f2 | awk '{print $1}'
else  
  echo "You must enter an interface name."
fi  

Here is the gist for the getip.sh

pub.sh:

#!/bin/bash
ifconfig eth0 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'  

Here is the gist for the pub.sh

priv.sh:

#!/bin/bash
ifconfig eth0:1 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'  

Here is the gist for the priv.sh

I usually drop the .sh put them all in /usr/local/bin on my servers. If you decide to place them there as well, remember to change owner, group and permission:

sudo chown root:root /usr/local/bin/_scriptName_  
sudo chmod 755 /usr/local/bin/_scriptName_  

Remember to change network interfaces name to match your own setup.

Hope this helps making someone else's life easier as well ;-)