自動化運維第一例

#!/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。要學會偷懶。

相關文章
相關標籤/搜索