码迷,mamicode.com
首页 > 系统相关 > 详细

添加网卡子接口ip地址shell脚本

时间:2017-07-16 17:29:00      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:ip地址   脚本   shell   


#!/bin/bash
#author wangning
#date 2017-7-15
#qq 1198143315
#Email 1198143315@qq.com

############################### define color ##############################
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
color="\033[0m"

################################## menu function #########################
menu(){
echo -e "
=========================
please select number 1-16
,add ip 10.0.2.x
or delete ip 10.0.2.x
$green  1.add ip $color
$red  2.delete ip $color
$yellow  3.exit $color   
=========================
"
}

################################ jude integer function #########################
jude_integer(){
read -p "please select 1 or 2 or 3:" num1
clear
expr $num1 + 1 &>/dev/null
if [ $? -ne 0 ];then
   echo -e "please input a $yellow integer number $color"
   continue 1
fi
}

############################### configure ip address function ######################
config_ip(){
if [ -z $num1 ];then
  echo -e "$yellow Can‘t be empty $color"
elif [ $num1 -gt 3 ];then
  echo -e "you must input a number $yellow less than 4 $color"
elif [ $num1 -eq 1 ];then
  read -p "please input number  1-16 add ip:" num2 
  ip addr add 10.0.2.${num2}/24 dev eth0:$num2
     if [ $? -eq 0 ];then
        echo -e "$green the ip 10.0.2.$num2 has added successful $color"
     else
        echo -e "$red the ip 10.0.2.$num2 has added failed $color"
     fi
elif [ $num1 -eq 2 ];then
  read -p "please input number 1-16 delete ip:" num3
  ip addr del 10.0.2.${num3}/24 dev eth0:$num3
     if [ $? -eq 0 ];then
        echo -e "$green the ip 10.0.2.$num3 has deleted successful $color"
     else
        echo -e "$red the ip 10.0.2.$num3 has deteted failed $color"
     fi
elif [ $num1 -eq 3 ];then
  exit 0
fi
}

################################### main function ###############################
main(){
while true
do
menu
jude_integer
config_ip
done
}

main


本文出自 “飞奔的骆驼” 博客,请务必保留此出处http://wn2100.blog.51cto.com/9915310/1947971

添加网卡子接口ip地址shell脚本

标签:ip地址   脚本   shell   

原文地址:http://wn2100.blog.51cto.com/9915310/1947971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!