RHL6.4 修改IP,主機名指令碼

Michael_DD發表於2015-09-28
RHL6.4 修改IP,主機名指令碼


[mwuser@szepayapp1 tmp]$ sh newly.sh --help
Usage: newly.sh IPADDR,HWADDR
[mwuser@szepayapp1 tmp]$ 

[mwuser@szepayapp1 tmp]$ cat newly.sh 
#!/bin/bash
hostcfg="/etc/sysconfig/network"
ifcfg="/etc/sysconfig/network-scripts/ifcfg-eth0"
udevcfg="/etc/udev/rules.d/70-persistent-net.rules"
GATEWAY=$(echo $1 | awk -F "." '{print $1"."$2"."$3"."1}')
HWADDR=$(ifconfig -a | awk '/HW/{print $5}')
intnum=$(ls /etc/sysconfig/network-scripts/ifcfg-eth*|wc -l)
 [ $intnum -lt 1 ] && echo "more than 1 interface,exit" && exit 3
 [ -z $1 ] && echo $"Usage: $0 IPADDR,HWADDR" && exit 2 
 [ -z $2 ] && echo $"Usage: $0 IPADDR,HWADDR" && exit 2
  sed -i '/HWADDR/'d $ifcfg
  sed -i '/IPADDR/'d $ifcfg
  sed -i '/GATEWAY/'d $ifcfg
  echo "IPADDR=$1" >> $ifcfg
  echo "GATEWAY=$GATEWAY" >> $ifcfg
  echo "HWADDR=$HWADDR" >> $ifcfg
  sed -i '/HOSTNAME/'d $hostcfg
  sed -i '/GATEWAY/'d $hostcfg
  echo "HOSTNAME=$2" >> $hostcfg
  rm -fr $udevcfg
  echo "$1 $2" >> /etc/hosts
  cat $ifcfg
  cat $hostcfg
  cat /etc/hosts

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1810628/,如需轉載,請註明出處,否則將追究法律責任。

相關文章