shell脚本自动化--bond
2016-03-22 11:31
417 查看
shell脚本自动化--bond
shell没什么基础,有客户要求需实现自动化配置bond的shell脚本,自己测试了好多次。
shell没什么基础,有客户要求需实现自动化配置bond的shell脚本,自己测试了好多次。
#!/bin/bash ###version 1.1#### if [ `whoami` = "root" ];then echo "user:root" else echo "you need root." exit fi ####获取IP,NETMASK,GATEWAY等信息### read -p "please input IPaddr:" IPaddr read -p "please input netmask:" Netmask read -p "please input gateway:" Gateway ###关闭NetworkManager### systemctl stop NetworkManager.service systemctl disable NetworkManager.service echo "NetworkManager.service have stopped" ####获取两个网卡的名称和MAC#### cd /etc/sysconfig/network-scripts/ eth=`ls | grep ifcfg | grep e | awk 'NR==1'| cut -b 7-9` eth_1=`ifconfig -a | grep $eth | awk -F: '{print $1}' | awk 'NR==1'` eth_2=`ifconfig -a | grep $eth | awk -F: '{print $1}' | awk 'NR==2'` eth_1_MAC=`ifconfig -a | grep ether | awk '{print $2}' | awk 'NR==1'` eth_2_MAC=`ifconfig -a | grep ether | awk '{print $2}' | awk 'NR==2'` ####写入配置文件###### ###bond0### echo "###bond0###" > /etc/sysconfig/network-scripts/ifcfg-bond0 echo "DEVICE=bond0" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "IPADDR=$IPaddr" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "NETMASK=$Netmask" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "GATEWAY=$Gateway" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "BONDING_OPTS="mode=1 miimon=100"" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "NM_CONTROLLED=no" >> /etc/sysconfig/network-scripts/ifcfg-bond0 echo "already config ifcfg-bond0!" ####eth_1#### echo "###ifcfg_$eth_1###" > /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "NAME=$eth_1" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "HWADDR=$eth_1_MAC" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "TYPE="Ethernet"" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "ONBOOT="yes"" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "MASTER=bond0" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "NM_CONTROLLED=no" >> /etc/sysconfig/network-scripts/ifcfg-$eth_1 echo "already config ifcfg-$eth_1!" ####eth_2#### echo "###ifcfg_$eth_2###" > /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "NAME=$eth_2" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "HWADDR=$eth_2_MAC" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "TYPE="Ethernet"" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "ONBOOT="yes"" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "MASTER=bond0" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "NM_CONTROLLED=no" >> /etc/sysconfig/network-scripts/ifcfg-$eth_2 echo "already config ifcfg-$eth_2!" #####alias########### echo "alias bond0 bonding" >> /etc/modprobe.d/bond0.conf #####重启network服务#### echo "system will reboot the network....." chkconfig network on /etc/init.d/network restart echo "you need to reboot your system!"
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- Shell 脚本编程陷阱
- shell字符串操作详解
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- Shell脚本解压rpm软件包
- Linux Shell 数组建立及使用技巧
- Shell脚本实现复制文件到多台服务器的代码分享
- Shell脚本实现批量替换文件内容
- Shell脚本实现的一个简易Web服务器例子分享
- linux Shell学习笔记第五天