码迷,mamicode.com
首页 > 其他好文 > 详细

新建虚拟机动配置脚本

时间:2015-08-08 21:33:08      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

[root@server12 ~]# cat ip-host-by-vision.sh 
#########################################################################
# File Name: ip-host-by-vision.sh
# Author: dty
# mail: 576786031@qq.com
# Created Time: Sat 08 Aug 2015 05:25:07 PM CST
#########################################################################
#!/bin/bash
IPDIR=/etc/sysconfig/network-scripts/ifcfg-eth0
HOSTDIR=/etc/sysconfig/network
read -p "please input what host number you want: " num
cat -> $IPDIR <<EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=no
IPADDR=172.25.254.$num
PREFIX=24
EOF
cat -> $HOSTDIR <<EOF
NETWORKING=yes
HOSTNAME=server$num.example.com
EOF
chkconfig iptables off
/etc/init.d/network restart
ping -w1 -c1 172.25.254.250  > /dev/null 2>&1
if [ $? -eq 0 ];then
    echo successful 
else
    echo failed
fi
sleep 2
##修改了IP,主机名 
UPDATEHOSTS(){
expect updatehosts.sh &  
sleep 8
if [ $? -eq 0 ];then
echo `grep NAME /etc/sysconfig/network|cut -d= -f2` >> /etc/hosts
else
    echo add hosts default, please try again!!!!!
fi
}
UPDATEHOSTS
read -p  "do you want reboot the machine...press yes or no."  want
case $want in
    YES|yes)
    sleep 1
    echo Now the machine will reboot please wait ..
    sleep 2
    reboot
    ;;
    NO|no)
    exit 1
    ;;
    *)
    echo "the usage (yes|no) please .." 
    ;;
esac


[root@server12 ~]# cat updatehosts.sh  //更新hosts文件
#########################################################################
# File Name: updatehosts.sh
# Author: dty
# mail: 576786031@qq.com
# Created Time: Sat 08 Aug 2015 06:50:30 PM CST
#########################################################################
#!/usr/bin/expect
spawn scp root@172.25.254.250:/etc/hosts /etc/hosts
expect "(yes/no)" {
send "yes\r"
expect "password"
sleep 2
send "redhat\r"
} "password"
sleep 2
send "redhat\r"
expect "100%"
expect eof


新建虚拟机动配置脚本

标签:

原文地址:http://my.oschina.net/loveleaf/blog/489554

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!