Created
November 18, 2014 05:30
-
-
Save nori-nori/f1682de1848a19e84b88 to your computer and use it in GitHub Desktop.
script for updating Mac Addresses on cloned VM of RHEL/CentOS6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
UdevRules=/etc/udev/rules.d/70-persistent-net.rules | |
mv -f ${UdevRules} ${UdevRules}.old | |
udevadm trigger --subsystem-match="net" --action add | |
sleep 5 | |
if [ ! -e "${UdevRules}" ]; then | |
exit 1 | |
fi | |
for devFile in /etc/sysconfig/network-scripts/ifcfg-eth* | |
do | |
# main | |
devName=${devFile##*-} | |
MacAddr=`grep ${devName} ${UdevRules} | awk '{print $4}' | sed -e 's/.*"\(.*\)",.*/\1/;'` | |
grep HWADDR "${devFile}" >/dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
sed -e "s/^HWADDR.*/HWADDR=${MacAddr}/" ${devFile} > /tmp/ifcfg.$$ | |
cp /tmp/ifcfg.$$ ${devFile} | |
rm -f /tmp/ifcfg.$$ | |
else | |
printf "HWADDR=${MacAddr}\n" >> ${devFile} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment