The shell script automatically modifies the IP information

  

#!/bin/sh# BY kerryhu# MAIL:[email protected]# This is a script that automatically modifies the network ip, mask, and gateway. #方法方法ip_mod IP_MOD, MASK_MOD, GW_MOD# Example: ip_mod 10.10.10.5 255.255.255.0 10.10.10.1

#where IP_MOD, MASK_MOD, GW_MOD are ip, mask, gw# to be changed to set variable PROC= /bin/sedIP_PATH=/etc/sysconfig/network-scripts/ifcfg-eth0GW_PATH=/etc/sysconfig/networkIP_PRI=`grep -i ipaddr $IP_PATH| Awk -F "=" '{printf $2 }'`MASK_PRI=`grep -i netmask $IP_PATH| Awk -F "=" '{printf $2}'`GW_PRI=`grep -i GATEWAY $GW_PATH| Awk -F "=" '{printf $2}'`IP_MOD=$1MASK_MOD=$2GW_MOD=$3

#Modify ip, mask, gw$PROC -i "s/$IP_PRI/$IP_MOD /g" $IP_PATH$PROC -i "s/$MASK_PRI/$MASK_MOD/g" $IP_PATH$PROC -i "s/$GW_PRI/$GW_MOD/g" $GW_PATH

#Restart NIC /etc/rc.d/init.d/network restart

Copyright © Windows knowledge All Rights Reserved