本篇内容介绍了“Shell怎么自动修改CentOS6网卡配置文件”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
#!/bin/bash # MY_ONBOOT="ONBOOT=yes" MY_BOOTPROTO="BOOTPROTO=static" MY_DEVICE="DEVICE="`ifconfig -a|grep HWaddr|awk {'print $1'}` MY_HWADDR="HWADDR="`ifconfig -a|grep HWaddr|awk {'print $5'}` MY_IPADDR="IPADDR="$1 MY_NETMASK="NETMASK="$2 MY_GATEWAY="GATEWAY="$3 MY_DNS="DNS1="$4 Flag1=0 Flag2=0 Flag3=0 Flag4=0 if [ $# -lt 4 ];then echo "Usage:./modif_ip.sh arg1[IPADDR] arg2[NETMASK] arg3[GATEWAY] arg4[DNS]." exit 5 fi if [ $# -gt 4 ];then echo "Usage:./modif_ip.sh arg1[IPADDR] arg2[NETMASK] arg3[GATEWAY] arg4[DNS]." exit 6 fi cat /etc/sysconfig/network-scripts/ifcfg-eth0 | while read myline do if [[ "$myline" =~ "ONBOOT" ]];then echo $MY_ONBOOT >> ifcfg-eth0 elif [[ "$myline" =~ "BOOTPROTO" ]];then echo $MY_BOOTPROTO >> ifcfg-eth0 elif [[ "$myline" =~ "DEVICE" ]];then echo $MY_DEVICE >> ifcfg-eth0 elif [[ "$myline" =~ "HWADDR" ]];then echo $MY_HWADDR >> ifcfg-eth0 elif [[ "$myline" =~ "IPADDR" ]];then Flag1=1 elif [[ "$myline" =~ "NETMASK" ]];then Flag2=1 elif [[ "$myline" =~ "GATEWAY" ]];then Flag3=1 elif [[ "$myline" =~ "DNS" ]];then Flag4=1 else echo $myline >> ifcfg-eth0 fi done if [ $Flag1 == 0 ];then echo $MY_IPADDR >> ifcfg-eth0 fi if [ $Flag2 == 0 ];then echo $MY_NETMASK >> ifcfg-eth0 fi if [ $Flag3 == 0 ];then echo $MY_GATEWAY >> ifcfg-eth0 fi if [ $Flag4 == 0 ];then echo $MY_DNS >> ifcfg-eth0 fi cp /root/ifcfg-eth0 /etc/sysconfig/network-scripts/ rm -rf /root/ifcfg-eth0
“Shell怎么自动修改CentOS6网卡配置文件”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。