原文链接:
IT运维专家网--"自由平等,互助分享!"
#!/bin/bash
#by FoxBin 2009-10-31 00:42
#注:用之前先看hosts里面主机名在第几列,oldname1的数值根据不同系统的hosts里主机名列的位置来awk取值
#首先修改/etc/sysconfig/network和/etchosts,最后用hostname,3个步骤修改主机名
nn="/etc/sysconfig/network"
nn1="/etc/hosts"
grep -n 'HOSTNAME' $nn > /tmp/aa
grep -n '127.0.0.1' $nn1 > /tmp/aa1
num=`awk -F":" '{print $1}' /tmp/aa`
num1=`awk -F":" '{print $1}' /tmp/aa1`
oldname=`awk -F"=" 'NR=="'$num'"{print $2}' $nn`
oldname1=`awk 'NR=="'$num1'"{print $2}' $nn1`
read newname
sed "s/${oldname}/${newname}/" $nn > /tmp/hostname
sed "s/${oldname1}/${newname}/" $nn1 > /tmp/hostname1
echo "" > $nn
echo "" > $nn1
cp -rf /tmp/hostname $nn
cp -rf /tmp/hostname1 $nn1
`hostname $newname`
说明:如果要用puppet的话在KS文件里面能否考虑添加修改主机名的脚本进来?
阅读(1634) | 评论(0) | 转发(0) |