shell获取Linux服务器I
#!/bin/bash#date: 2016.03.20
#The script for display ipaddress.
#Author:xusjclo
read -p "please input the device": name
case $name in
eth0)
IP=`ifconfig|grep -A1 $name |grep -v Link | awk '{print $2}' |cut -d : -f 2`
echo "The $name's ip address is $IP"
;;
eth1)
IP=`ifconfig |grep -A1 $name |grep -v Link |awk '{print $2}' | cut -d : -f 2`
echo "The $name's ip address is $IP"
;;
eth2)
IP=`ifconfig |grep -A1 $name |grep -v Link |awk '{print $2}' | cut -d : -f 2`
echo "The $name's ip address is $IP"
;;
eth3)
IP=`ifconfig |grep -A1 $name |grep -v Link |awk '{print $2}' | cut -d : -f 2`
echo "The $name's ip address is $IP"
;;
eth4)
IP=`ifconfig |grep -A1 $name |grep -v Link |awk '{print $2}' | cut -d : -f 2`
echo "The $name's ip address is $IP"
;;
*)
echo "Usage eth0|eth1|eth2|eth3|em1|em2|em3|em4"
esac
页:
[1]