写了一个用脚本实现用交互模式实现网络地址的修改的bash脚本,给大家分享一下
#!/bin/bash
read -p "qing shu ru ni xiang she zhi de wang ka:" wk
if [ !-z $wk ];then
echo "ci wang ka bu cun zai !"
exit 9
fi
read -p "please enter the ip type you want,dhcp or static:" fs
if [ $fs == 'dhcp' ];then
m=`grep BOOTPROTO /etc/sysconfig/network-scripts/ifcfg-$wk`
sed -i "1,$ s/$m/BOOTPROTO\=dhcp/g" /etc/sysconfig/network-scripts/ifcfg-$wk
elif [ $fs == static ];then
l=`grep BOOTPROTO /etc/sysconfig/network-scripts/ifcfg-$wk`
sed -i "1,$ s/$l/BOOTPROTO\=static/g" /etc/sysconfig/network-scripts/ifcfg-$wk
for i in IPADD NETMASK GATEWAY
do
read -p "please enter $i:" k
w=`grep $i /etc/sysconfig/network-scripts/ifcfg-$wk`
sed -i "1,$ s/$w/$i\=$k/g" /etc/sysconfig/network-scripts/ifcfg-$wk
echo "$i=$k"
done
fi
ifdown $wk
ifup $wk
cat /etc/sysconfig/network-scripts/ifcfg-$wk
转载于:https://blog.51cto.com/qingzhu/579702