#!/bin/bash
#Purpose: To show the IP address of a machine
#Author:Surendra Anne
#Date: 2012-09-11
#Licence: GPLv3
for i in `ifconfig | cut -d” ” -f1 | sort | grep -v ‘^$’`
do
if ifconfig $i | grep addr: &> /dev/null
then
echo “The interface $i have IP Address:$(ifconfig $i | grep addr: | awk ‘{print $2}’ | cut -d”:” -f2)”
fi
done
Your are free to add/modify this script and use it for your purpose. Some of the tools used here are
SORT command
cut command
ifconfig command
grep command
redirection operation
echo command
awk command
for loop
if statement
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018