defect 4079: to support rh7 that hostname is cfged in /etc/hostname. Check the existence of /etc/hostname, use itif yes, otherwise use /etc/sysconfig/network

This commit is contained in:
daniceexi 2014-05-28 10:27:41 -04:00
parent 25b2fee331
commit 813fba8c6b
6 changed files with 30 additions and 14 deletions

View File

@ -100,8 +100,8 @@ change_host_name()
if [ "$str_os_type" = "sles" ];then
echo "Persistently changing the hostname not implemented yet."
#debian ubuntu
elif [ "$str_os_type" = "debian" ];then
#debian ubuntu and rh7
elif [ -f "/etc/hostname" ];then
conf_file="/etc/hostname"
echo "$str_hostname" > $conf_file
else

View File

@ -36,8 +36,8 @@ change_host_name()
if [ "$str_os_type" = "sles" ];then
echo "Persistently changing the hostname not implemented yet."
#debian ubuntu
elif [ "$str_os_type" = "debian" ];then
#debian ubuntu and rh7
elif [ -f "/etc/hostname" ];then
conf_file="/etc/hostname"
echo "$str_hostname" > $conf_file
else

View File

@ -251,7 +251,11 @@ then
then
BOOT_HOSTNAME=$(lsattr -El inet0 -a hostname | awk '{print $2}')
else # Linux
BOOT_HOSTNAME=`grep HOSTNAME /etc/sysconfig/network | cut -f 2 -d "="`
if [ -f "/etc/hostname" ]; then
BOOT_HOSTNAME=`cat /etc/hostname`
else
BOOT_HOSTNAME=`grep HOSTNAME /etc/sysconfig/network | cut -f 2 -d "="`
fi
fi
hostname ${BOOT_HOSTNAME}
fi

View File

@ -393,11 +393,15 @@ elif [ "$1" = "-s" ];then
fi
fi
hostname $NODE
grep -i "HOSTNAME" /etc/sysconfig/network
if [ $? -eq 0 ];then
sed -i "s/.*HOSTNAME.*/HOSTNAME=${NODE}/i" /etc/sysconfig/network
if [ -f "/etc/hostname" ]; then
echo $NODE > /etc/hostname
else
echo "HOSTNAME=${NODE}" >> /etc/sysconfig/network
grep -i "HOSTNAME" /etc/sysconfig/network
if [ $? -eq 0 ];then
sed -i "s/.*HOSTNAME.*/HOSTNAME=${NODE}/i" /etc/sysconfig/network
else
echo "HOSTNAME=${NODE}" >> /etc/sysconfig/network
fi
fi
fi
exit 0

View File

@ -63,7 +63,11 @@ then
else
#RedHat uses /etc/sysconfig/network-scripts/ifcfg-eth<x>
NICFILEPRE="/etc/sysconfig/network-scripts/ifcfg-"
sed -i "s/HOSTNAME.*/HOSTNAME=`hostname`/" /etc/sysconfig/network
if [ -f "/etc/hostname" ]; then # for rh7
echo `hostname` >/etc/hostname
else
sed -i "s/HOSTNAME.*/HOSTNAME=`hostname`/" /etc/sysconfig/network
fi
if [ ! -z "$defgw" ]; then
echo "GATEWAY=$defgw" >> /etc/sysconfig/network
fi

View File

@ -16,11 +16,15 @@ device_names=`ip link |grep "BROADCAST" |awk '{print $2}' | sed s/://`
str_cfg_file=''
if [ -d "/etc/sysconfig/network-scripts/" ];then
#redhat
grep -i HOSTNAME /etc/sysconfig/network
if [ $? -eq 0 ];then
sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /etc/sysconfig/network
if [ -f "/etc/hostname" ]; then #RH7
echo $HOSTNAME > /etc/hostname
else
echo "HOSTNAME=$HOSTNAME" >> /etc/sysconfig/network
grep -i HOSTNAME /etc/sysconfig/network
if [ $? -eq 0 ];then
sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /etc/sysconfig/network
else
echo "HOSTNAME=$HOSTNAME" >> /etc/sysconfig/network
fi
fi
for i in $device_names;do
str_cfg_file="/etc/sysconfig/network-scripts/ifcfg-$i"