自动化运维第一例

#!/bin/bashvim

service iptables stopbash

chkconfig iptables offssh

setenforce 0ide

dhclient &>/dev/nullspa

echo "dhclient is ok"rest

rm -rf /etc/ssh/ssh_host_*ip

a=`ip addr | grep eth0 |wc -l`get

b=`ip addr | grep eth1 |wc -l` 虚拟机

if [ $a -ne 0 ] ;thenit

echo -e  "DEVICE=eth0\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static\nNAME=eth0\nIPADDR=`ifconfig eth0 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}'`\nGATEWAY=` ifconfig eth0 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}' |awk -F '.' '{print $1"."$2"."$3}'`.2\nNETMASK=255.255.255.0\nDNS1=202.106.0.20\nDNS2=180.76.76.76"  > /etc/sysconfig/network-scripts/ifcfg-eth0

fi

echo "eth0:ip is `ifconfig eth0 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}'`"

if [ $b -ne 0 ] ;then

echo -e  "DEVICE=eth1\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static\nNAME=eth1\nIPADDR=`ifconfig eth1 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}'`\nGATEWAY=` ifconfig eth1 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}' |awk -F '.' '{print $1"."$2"."$3}'`.2\nNETMASK=255.255.255.0\nDNS1=202.106.0.20\nDNS2=180.76.76.76"  > /etc/sysconfig/network-scripts/ifcfg-eth1

fi

echo "eth1:ip is `ifconfig eth1 | grep Bcast | awk -F ':' '{print $2}' | awk '{print $1}'`"

service network restart &> /dev/null

chkconfig network on

echo "network.service is ok"

yum clean all &>/dev/null

yum makecache &>/dev/null

echo "yum is ok"

yum install -y  vim openssh-clients wget mget &>/dev/null

echo "welcome here,thank you"

每次装虚拟机就要配置ip,长时间这样我已经累了,因而乎写了个脚本开机运行下就ok。要学会偷懒。

相关文章
相关标签/搜索