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

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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



本文转自 茁壮的小草 51CTO博客,原文链接:http://blog.51cto.com/wn2100/1947971,如需转载请自行联系原作者
相关文章
|
3天前
|
Shell
蓝易云 - 简单shell脚本的编写教程
以上就是编写一个基本Shell脚本的步骤。当然,Shell脚本可以做的远不止这些,你可以使用变量,控制结构(如if语句和循环),以及各种Shell命令和功能来编写更复杂的脚本。
11 1
|
4天前
|
Shell 调度
Shell脚本中的if条件判断语句
Shell脚本中的if条件判断语句
|
4天前
|
Shell
蓝易云 - 简单shell脚本的编写教程
以上就是编写一个基本Shell脚本的步骤。当然,Shell脚本可以做的远不止这些,你可以使用变量,控制结构(如if语句和循环),以及各种Shell命令和功能来编写更复杂的脚本。
5 0
|
5天前
|
机器学习/深度学习 Unix Java
技术笔记:Linux之Shell脚本编程(一)
技术笔记:Linux之Shell脚本编程(一)
|
8天前
|
Shell
Shell脚本之条件语句if总结
Shell脚本之条件语句if总结
|
Shell Python Perl
python与shell校验IP地址合法性
python校验IP地址合法性 执行效果: python代码: [root@yang python]# vi check_ip.py #!/usr/bin/python import os,sys def check_ip(ipaddr): import sys addr=ipaddr.
921 0
|
15天前
|
监控 Shell Linux
Linux的Shell脚本详解
Linux的Shell脚本详解
|
19天前
|
Shell
shell脚本
shell脚本
18 2
|
27天前
|
Ubuntu Java Linux
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
38 2