- #!/bin/bash
- #######################################################################################################
- # Author : lkl_1981
- # Email : lkl_1981@163.com
- # QQ : 37547134
- # Create time : 2012-07-01
- # Last time : 2012-07-02
- # Useage : create batch virtual ip only suppot c class ip of currnet version
- #########################################################################################################
- #eth="ifcfg-eth0"
- #ip_start=50
- #ip_length=10
- print_help()
- {
- echo "Usage: vmeth.sh [OPTION]"
- echo "e.g.: vmeth -i ifcfg-eth0 -ips 192.168.0.200 -iplen 5"
- }
- while [ $# -gt 0 ]; do
- case $1 in
- -h|--help)
- print_help
- exit 0
- ;;
- -V|--version)
- print_version
- exit 0
- ;;
- -ips|--ipstart)
- ip_start=$2
- shift 2
- ;;
- -iplen|--iplength)
- ip_length=$2
- shift 2
- ;;
- -i|--interface)
- eth=$2
- shift 2
- ;;
- -v|--verbose)
- verbose=true
- shift
- ;;
- --)
- shift
- break
- ;;
- *)
- echo "Internal Error: option processing error: $1" 1>&2
- exit 1
- ;;
- esac
- done
- #echo $eth
- #echo $ip_start
- #echo $ip_length
- #:<<BLOCK
- ip=()
- ip[0]=`echo $ip_start|cut -d "." -f1`
- ip[1]=`echo $ip_start|cut -d "." -f2`
- ip[2]=`echo $ip_start|cut -d "." -f3`
- ip[3]=`echo $ip_start|cut -d "." -f4`
- eth_post=`expr substr $eth 7 4`
- hwaddr=`ifconfig $eth_post|grep -i "hwaddr"|awk '{print $5}'`
- for((i=1;i<=ip_length;i++));do
- echo "DEVICE=$eth_post:"$i>>$eth":"$i
- echo "BOOTPROTO=static">>$eth":"$i
- echo "HWADDR="$hwaddr>>$eth":"$i
- echo "IPADDR="${ip[0]}"."${ip[1]}"."${ip[2]}"."${ip[3]}>>$eth":"$i
- echo "NETMASK=255.255.255.0">>$eth":"$i
- echo "ONBOOT=yes">>$eth":"$i
- let "ip[3]=${ip[3]}+1"
- done
- #BLOCK