#! /bin/bash # Run this script on a freshly installed compute-node to establish intranet connection to the frontend via eth0-switch, as well as to the internet via eth1 (if eth1 is present). It will try to identify the number $ipaddlastnumber that should be assigned to the new node automatically by reading information from /etc/hosts from the frontend. # 1 set temporary ip for eth0 to 192.168.1.999 ################################# # Check the identities of the network cards. Select one as the 'eth0' (to guess) and then modify the corresponding /etc/sysconfig/network-scripts/ifcfg-$nc nc0=$(lshw -class network | grep -E 'Ethernet interface|logical name' | grep 'logical name' | awk '{print $3}' | awk '!/vir/' | tail -n1) echo $nc0 'is chosen as the eth0, internal network port. To modify /etc/sysconfig/network-scripts/ifcfg-"$nc".' ls /etc/sysconfig/network-scripts/ifcfg-$nc0 cp /etc/sysconfig/network-scripts/ifcfg-$nc0 /etc/sysconfig/network-scripts/ifcfg-$nc0.orig.1 # replacement: sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/IPV6INIT="yes"/IPV6INIT="no"/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/DHCPCLASS=//g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/ONBOOT=no/ONBOOT="yes"/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/NM_CONTROLLED="yes"//g' /etc/sysconfig/network-scripts/ifcfg-$nc0 ## not to have any NM_control sed -i 's/IPADDR=192.168.1.21//g' /etc/sysconfig/network-scripts/ifcfg-$nc0 ## remove the line IPADDR=192.168.1.26 if present # append echo IPADDR=192.168.1.999 >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'NETMASK=255.255.0.0' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'DNS1=192.168.1.10' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'DOMAIN=local' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'GATEWAY=192.168.1.10' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 cat /etc/sysconfig/network-scripts/ifcfg-$nc0 | sort | uniq > temp.ifcfg mv temp.ifcfg /etc/sysconfig/network-scripts/ifcfg-$nc0 ############################################################ echo '' echo 'ifconfig before service network restart' ifconfig echo '' service network restart echo '' echo 'ifconfig after service network restart' ifconfig echo '' checkping=$(ping -q -c1 -W 5 192.168.1.10 | awk 'NR==4 {print $4}') if [ $checkping -eq 0 ] then echo $i is not responding to ping after 5 second fi if [ $checkping -eq 1 ] then echo 192.168.1.10 is responding to ping within 1 second. cat > temp.dat << __EOF__ cat /etc/hosts | sort | uniq | grep '192.168' | awk '{print $1}' | awk -F "." '{print $4}'| awk 'END {print}' __EOF__ command=$(cat temp.dat) lastindex=$(ssh -X -Y 192.168.1.10 "$command") echo '$lastindex=' $lastindex nextindex=$(( $lastindex + 1 )) rm -rf temp.dat fi fi echo 'nextindex=' $nextindex echo '/etc/sysconfig/network-scripts/ifcfg-$nc0=' cat /etc/sysconfig/network-scripts/ifcfg-$nc0