Shell自动修改CentOS6网卡配置文件
2015-11-24 15:39
896 查看
#!/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
本文出自 “Jessen Liu的博文” 博客,请务必保留此出处http://zkhylt.blog.51cto.com/3638719/1716397
相关文章推荐
- expect shell python glpi exception.mac
- shell任务不受意外中断影响的常见方法
- 使用 Screen 创建并管理多个 shell
- PowerShell,远程操作,读写复制备份文件
- git中用shell命令停止nodejs服务
- 定时执行powershell获取邮箱登录数据
- 如何使用XShell登录亚马逊EC2云服务器
- windows使用xshell免密码登陆远程Linux服务器教程
- bash programming
- [PowerShell Utils] Remotely install Hyper-V and Failover Cluster feature on a list of windows 2012 servers
- [PowerShell Utils] Automatically Change DNS and then Join Domain
- Linux Bash Shell编程快速入门
- Shell参数
- shell 中的<,<<,>,>>
- linux shell 学习笔记--文件测试符
- linux shell 学习笔记--比较操作
- linux shell 学习笔记--变量声明与赋值,循环
- linux shell 学习笔记--内部命令学习
- 【转载】我的一些简单的shell脚本实例
- shell 字符串切分成数组