更改网卡名脚本
作者:互联网
#!/bin/bash
pwd=$(pwd)
cata=$pwd/wangyu
net=$cata/network_name
file=/etc/sysconfig/network-scripts/ifcfg-
if [ ! -d $cata ];then
mkdir $cata
fi
if [ ! -f $net ];then
touch $net
echo "Please write network name "
fi
former_name=$(cat $net |awk '{print $1}')
for i in $former_name
do
wen_name=$(cat $net |grep $i |awk '{print $2}')
cp $file$i $cata
sed -i "/NAME/s/$i/$wen_name/" $file$i
sed -i "/DEVICE/s/$i/$wen_name/" $file$i
sed -i "/ONBOOT/s/no/yes/" $file$i
mac=$(ifconfig $i |grep ether|awk '{print $2}')
echo HWADDR=$mac >> $file$i
echo ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{type}==\"32\", ATTR{address}==\"$mac\", NAME=\"$wen_name\" >> /etc/udev/rules.d/70-persistent-ipoib.rules
mv $file$i $file$wen_name
done
直接执行脚本,他会在当前位置创建目录生成文件。你只要把要更改的的网卡原名和新名写入就行。完后再执行脚本。
标签:脚本,cata,name,更改,wen,echo,网卡,file,net 来源: https://blog.csdn.net/qq_42912339/article/details/86598942