第一版见:https://blog.csdn.net/zhaoxinfan/article/details/86256524
这里是对原来版本进行了优化,节省了板卡不改变槽位下的启动时间。脚本中如果板卡所在的槽位、插箱和原有配置的一样就无须重复配置,否则重新进行配置。
#!/bin/bash vpx_eth_name=("enp2s0f0" "enp2s0f1" "enp7s0" "enp9s0f0" "enp9s0f1" "enp9s0f2" "enp9s0f3") net_vpx_autocfg() { echo "vpx_net_autocfg" vpx_get_eth_name=(${vpx_eth_name[*]}) cd /opt/pet get_info=`./slot_test` get_slotid=$(echo $get_info | cut -d ' ' -f 1) get_chassisid=$(echo $get_info | cut -d ' ' -f 2) get_rackid=$(echo $get_info | cut -d ' ' -f 3) org_slotid=$(echo `hostname` | cut -d '-' -f 1 | tr -cd "[0-9]") org_chassisid=$(echo `hostname` | cut -d '-' -f 2) #printf 'slot is %d\n' $get_slotid #printf 'chasis is %d\n' $get_chassisid #printf 'rack is %d\n' $get_rackid if [ $get_slotid == $org_slotid ] && [ $get_chassisid == $org_chassisid ] then echo "do not change network" else hostnamectl set-hostname node${get_slotid}-${get_chassisid} cd /opt/pet/net unalias cp cp ifcfg-enp* /etc/sysconfig/network-scripts/ cd /etc/sysconfig/network-scripts/ get_ip4=$(expr $get_slotid \* 10 + $get_chassisid) ifdown ifcfg-${vpx_get_eth_name[0]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[0]} echo "IPADDR=192.168.80.$get_ip4" >> ifcfg-${vpx_get_eth_name[0]} ifup ifcfg-${vpx_get_eth_name[0]} ifdown ifcfg-${vpx_get_eth_name[1]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[1]} echo "IPADDR=192.168.90.$get_ip4" >> ifcfg-${vpx_get_eth_name[1]} ifup ifcfg-${vpx_get_eth_name[1]} ifdown ifcfg-${vpx_get_eth_name[2]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[2]} echo "IPADDR=192.168.100.$get_ip4" >> ifcfg-${vpx_get_eth_name[2]} ifup ifcfg-${vpx_get_eth_name[2]} ifdown ifcfg-${vpx_get_eth_name[3]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[3]} echo "IPADDR=192.168.3.$get_ip4" >> ifcfg-${vpx_get_eth_name[3]} ifup ifcfg-${vpx_get_eth_name[3]} ifdown ifcfg-${vpx_get_eth_name[4]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[4]} echo "IPADDR=192.168.4.$get_ip4" >> ifcfg-${vpx_get_eth_name[4]} ifup ifcfg-${vpx_get_eth_name[4]} ifdown ifcfg-${vpx_get_eth_name[5]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[5]} echo "IPADDR=192.168.5.$get_ip4" >> ifcfg-${vpx_get_eth_name[5]} ifup ifcfg-${vpx_get_eth_name[5]} ifdown ifcfg-${vpx_get_eth_name[6]} sed -i '/IPADDR=/d' ifcfg-${vpx_get_eth_name[6]} echo "IPADDR=192.168.6.$get_ip4" >> ifcfg-${vpx_get_eth_name[6]} ifup ifcfg-${vpx_get_eth_name[6]} sleep 1 systemctl stop network.service sleep 1 systemctl start network.service fi } net_vpx_autocfg