系統mirror 後 ,修正mac 用的小程式.

GitHub

#!/bin/bash
echo "********************************************************"
echo "*                                                      *"
echo "* WARNING : This tool is only used for RHEL 6.4 x86_64 *"
echo "*                                                      *"
echo "********************************************************"
echo
echo "This host has nics as below :"
echo
dmesg | grep :..:..: |grep -v bond| grep -Po 'eth.|eth..'
dmesg | grep :..:..: |grep -v bond| grep -Po '..:..:..:..:..:..'
echo
echo "compare with rules.d and correct it !!!"
echo

read -p "***** please enter new ip ***** : " nip
read -p "***** please enter new gateway ***** : " ngw

echo
echo
echo "ip : $nip "
echo "gateway : $ngw "
echo
echo
read -p "Is it right ?? [Y|N]" ans


if [ "$ans" == "Y" ] || [ "$ans" == "y" ] || [ "$ans" == "yes" ]; then


f1=$(dmesg | grep -m 1 :..:..: | grep -v bond | grep -Po 'eth.|eth..' | sed -n 's/eth//p')
nil=$(dmesg | grep :..:..: | grep -v bond | grep -Po 'eth.|eth..' | sed -n 's/eth//p' | tail -n 1)


rm -f /etc/udev/rules.d/70-persistent-net.rules

sed -i '/IPADDR/d' /etc/sysconfig/network-scripts/ifcfg-br0
sed -i '/GATEWAY/d' /etc/sysconfig/network-scripts/ifcfg-br0
echo IPADDR=$nip >> /etc/sysconfig/network-scripts/ifcfg-br0
echo GATEWAY=$ngw >> /etc/sysconfig/network-scripts/ifcfg-br0

declare -i y=0

for ((x=$f1;x<=$nil;x=x+1))

do
sed -i '/DEVICE/d' /etc/sysconfig/network-scripts/ifcfg-eth$x
sed -i '/HWA/d' /etc/sysconfig/network-scripts/ifcfg-eth$x
mac=$(dmesg | grep :..:..: |grep -v bond|grep eth$x: |  grep -Po '..:..:..:..:..:..')
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$mac\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"eth$y\"" >> /etc/udev/rules.d/70-persistent-net.rules
mv /etc/sysconfig/network-scripts/ifcfg-eth$x /etc/sysconfig/network-scripts/ifcfg-eth$y
echo HWADDR=$mac >> /etc/sysconfig/network-scripts/ifcfg-eth$y
echo DEVICE=eth$y >> /etc/sysconfig/network-scripts/ifcfg-eth$y
y=y+1

done




echo
echo
echo "Good Job !!! "
echo

udevadm trigger
udevadm control --reload-rules
service network restart
else


echo
echo "Please check again!!! "
echo "Or you can contact Dino !!!"
echo
echo

fi



沒有留言:

張貼留言

非看不可

【超好用】貼圖快速裁切,極速上架。

輕鬆自製 LINE 貼圖!免安裝的超強網頁版「簡單的圖片工具」推薦 裁切、去背、標註一氣呵成,專為貼圖創作者打造的高效神器 很多創作者在製作 LINE 貼圖時,最常遇到的痛點就是: 尺...