UUIDからシリアルナンバー方式への変更を行ったので、以前書いたこちらのスクリプトも書き換えた。
以下に外部ファイルとなる「host.list」及び「setip.sh」を記載する。
●host.list
hostname,serialno,defaultgw,nic0,nic1
Test-CentOS001,VMware-56 4d 33 c9 f6 32 ab 40-14 88 00 e9 ca 90 d0 59,192.168.0.1,192.168.0.31/24,172.26.0.31/24
Test-CentOS002,VMware-56 4d ab 56 0a e5 9c d2-85 ed cf e9 7f 5a 9e 64,192.168.0.1,192.168.0.32/24,172.26.0.32/24
Test-CentOS003,VMware-56 4d f1 63 d8 10 26 5b-56 70 7d 08 1c 45 71 6f,192.168.0.1,192.168.0.33/24,172.26.0.33/24
変わったところとしては、今までUUIDが記述されていた箇所にシリアルナンバーが記述されただけである。
●setip.sh
#!/bin/sh
LIST="./host.list"
NIC0="eth0"
NIC1="eth1"
SCRIPT_DIR=`dirname $0`
cd $SCRIPT_DIR
MYSERIAL_CD=`dmidecode -t system | grep Serial | awk 'BEGIN { FS=": ";} { print $2}'`
IFCFGNIC0="ifcfg-${NIC0}"
IFCFGNIC1="ifcfg-${NIC1}"
if [ -z `cat $LIST | grep "$MYSERIAL_CD"` ]; then
echo "It did not exist in ["$ LIST"] within ["$ MYSERIAL_CD"]"
echo ""
exit 1
fi
#Host Name
HOSTNAME=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $1 }'`
#Default Gateway
GATEWAY=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $3 }' | awk 'BEGIN {FS="/"} {print $1}'`
#NIC0
NIC0_IPADDR=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $4 }' | awk 'BEGIN {FS="/"} {print $1}'`
NIC0_PREFIX=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $4 }' | awk 'BEGIN {FS="/"} {print $2}'`
NIC0_HWADDR=`ifconfig $NIC0 | grep HWaddr | awk '{print $5}'`
#NIC1
NIC1_IPADDR=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $5 }' | awk 'BEGIN {FS="/"} {print $1}'`
NIC1_PREFIX=`cat $LIST | grep "$MYSERIAL_CD" | awk 'BEGIN {FS=","} { print $5 }' | awk 'BEGIN {FS="/"} {print $2}'`
NIC1_HWADDR=`ifconfig $NIC1 | grep HWaddr | awk '{print $5}'`
#create ifcfg-*
cd /etc/sysconfig/network-scripts
#ifcfg-NIC0
echo "DEVICE=$NIC0" > $IFCFGNIC0
echo "TYPE=Ethernet" >> $IFCFGNIC0
echo "ONBOOT=yes" >> $IFCFGNIC0
echo "NM_CONTROLLED=yes" >> $IFCFGNIC0
echo "BOOTPROTO=none" >> $IFCFGNIC0
echo "IPADDR=$NIC0_IPADDR" >> $IFCFGNIC0
echo "PREFIX=$NIC0_PREFIX" >> $IFCFGNIC0
echo "GATEWAY=$GATEWAY" >> $IFCFGNIC0
echo "DEFROUTE=yes" >> $IFCFGNIC0
echo "IPV4_FAILURE_FATAL=yes" >> $IFCFGNIC0
echo "IPV6INIT=no" >> $IFCFGNIC0
echo "NAME=\"System $NIC0\"" >> $IFCFGNIC0
echo "HWADDR=$NIC0_HWADDR" >> $IFCFGNIC0
#ifcfg-NIC1
echo "DEVICE=$NIC1" > $IFCFGNIC1
echo "TYPE=Ethernet" >> $IFCFGNIC1
echo "ONBOOT=yes" >> $IFCFGNIC1
echo "NM_CONTROLLED=yes" >> $IFCFGNIC1
echo "BOOTPROTO=none" >> $IFCFGNIC1
echo "IPADDR=$NIC1_IPADDR" >> $IFCFGNIC1
echo "PREFIX=$NIC1_PREFIX" >> $IFCFGNIC1
echo "DEFROUTE=yes" >> $IFCFGNIC1
echo "IPV4_FAILURE_FATAL=yes" >> $IFCFGNIC1
echo "IPV6INIT=no" >> $IFCFGNIC1
echo "NAME=\"System $NIC1\"" >> $IFCFGNIC1
echo "HWADDR=$NIC1_HWADDR" >> $IFCFGNIC1
#Network Restart
/etc/init.d/network restart
cd /etc/sysconfig
echo "NETWORKING=yes" > network
echo "HOSTNAME=$HOSTNAME" >> network
echo "GATEWAY=$GATEWAY" >> network
こちらも、dmidecodeで取得する対象をシリアルナンバーにしただけだ。