fix defect #4146 post.rh.common scipt has ifconfig that does work even on Redhat6

This commit is contained in:
immarvin 2014-05-30 03:12:08 -07:00
parent 2b92556a12
commit 53374908bf

View File

@ -13,7 +13,8 @@ if [ -z "$PRINIC" ]
then
for karg in $(cat /proc/cmdline |sed -e 's/-/:/g' -e 's/ /\n/g'); do
if [ "${karg%%=*}" = "BOOTIF" ]; then
export PRINIC=`ifconfig -a|grep -i "hwaddr ${karg#*=01:}"|awk '{print $1}'`
#export PRINIC=`ifconfig -a|grep -i "hwaddr ${karg#*=01:}"|awk '{print $1}'`
export PRINIC=`ip -o link|grep -i "${karg#*=}"|awk '{print $2}'|sed s/://`
fi
done
if [ -z "$PRINIC" ]; then
@ -24,13 +25,16 @@ if [ -z "$PRINIC" ]
then
export PRINIC=eth0
elif [[ `echo "$PRINIC" | grep -sqE ^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+$ ;echo $?` == "0" ]]; then
export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'`
#export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'`
export PRINIC=`ip -o link|grep -i "$PRINIC"|awk '{print $2}'|sed s/://`
fi
IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}')
#IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}')
IP=$(ip addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}')
if [ -z $IP ]
then
dhclient eth0
IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}')
#IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}')
IP=$(ip addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}')
fi
export HOSTNAME=$(host $IP 2>/dev/null | awk '{print $5}' | awk -F. '{print $1}')