备份
IP-MAC-Plan.csv
RACK_ID |
Host_ID |
Host_Name |
Host_IP |
16 |
1 |
Host1 |
192.168.16.1 |
16 |
2 |
Host2 |
192.168.16.2 |
16 |
3 |
Host3 |
192.168.16.3 |
16 |
4 |
Host4 |
192.168.16.4 |
16 |
5 |
Host5 |
192.168.16.5 |
17 |
1 |
Host6 |
192.168.17.1 |
#!/bin/bash
sut_conf=/etc/dhcp/host_list/sut.conf list=IP-MAC-Plan.csv RowNum=$(wc -l $list | awk '{printf $1}') NicPortNum=10
echo " #option domain-name-servers 192.168.1.98,192.168.1.99; default-lease-time 21600; max-lease-time 43200; subnet 192.168.0.0 netmask 255.255.0.0 { #option routers 192.168.1.1; pool{ failover peer "dhcp"; range 192.168.1.1 192.168.200.200; } }
" > $sut_conf
for ((i=2; i<=$RowNum;i++)) do HostIP=$(sed -n "$i"p $list |awk -F "," '{printf $4}') third=$(echo $HostIP | awk -F "." '{printf $3}') forth=$(echo $HostIP | awk -F "." '{printf $4}') echo $HostIP #echo $third #echo $forth for ((j=1; j<=$NicPortNum; j++)) do ip3=$third ip4=$(($forth*10+10+$j-1)) SUTIP=192.168.$ip3.$ip4 #echo $ip mac5=$(echo "obase=16;$ip3"|bc) mac6=$(echo "obase=16;$ip4"|bc) SUTMAC=00:00:00:00:$mac5:$mac6 #echo $mac echo " host ${HostIP}_${j} { hardware ethernet $SUTMAC; fixed-address $SUTIP; }" >> $sut_conf done
done
生成文件: #option domain-name-servers 192.168.1.98,192.168.1.99; default-lease-time 21600; max-lease-time 43200; subnet 192.168.0.0 netmask 255.255.0.0 { #option routers 192.168.1.1; pool{ failover peer "dhcp"; range 192.168.1.1 192.168.200.200; } }
host 192.168.16.1_1 { hardware ethernet 00:00:00:00:10:14; fixed-address 192.168.16.20; }
host 192.168.16.1_2 { hardware ethernet 00:00:00:00:10:15; fixed-address 192.168.16.21; }
host 192.168.16.1_3 { hardware ethernet 00:00:00:00:10:16; fixed-address 192.168.16.22; }
host 192.168.16.1_4 { hardware ethernet 00:00:00:00:10:17; fixed-address 192.168.16.23; } (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|