学习笔记之ubuntu修改固定IP脚本
2024-10-19 09:34:33
一、shell脚本编程
二、正则表达式
三、linux修改IP的方法
#!/bin/bash cd /etc/network/ stty erase '^?' write_interfaces()
{
echo "auto lo
iface lo inet loopback auto eth0
iface eth0 inet static
address $
netmask 255.255.255.0
gateway $
" > interfaces
} reboot_fun()
{
echo "reboot now?(Y/N)"
read reb_in if [[ ${reb_in} = $'Y' || ${reb_in} = $'y' ]]
then
echo "reboot now"
reboot
else
echo "pls reboot if you can not ping the IP"
fi
} ping_func()
{
ping -c $set_IP && result= || result=
if [ $result -eq ]
then
{
echo "set Ip conflict"
continue
IP_INPUT=
}
fi if [ $result -eq ]
then
{
echo "IP is ok:$set_IP" write_interfaces $set_IP $GateWay
/etc/init.d/networking reload
/etc/init.d/networking restart
echo "set ok"
IP_INPUT=
}
fi
} echo "set IP into the main.cpp"
IP_INPUT= while [ $IP_INPUT -eq ]
do
echo "input IP"
read set_IP -n if [[ $set_IP =~ ^([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])$ ]]
then
echo "input gateway"
read GateWay arr_IP=${set_IP//./ }
arr_IP=($arr_IP)
arr_gw=${GateWay//./ }
arr_gw=($arr_gw) for arr in
do
if [ ${arr_IP[$arr]} == ${arr_gw[$arr]} ]
then
echo "arr_IP:${arr_IP[$arr]}"
else
echo "error IP :$set_IP"
continue
fi
done ping_func
fi
done reboot_fun
最新文章
- python 单例模式
- 【Hawk】入门教程(1)——从URL开始
- Swift - UIColor16进制编码与RGB格式互相转换
- 纯手写SpringMVC架构,用注解实现springmvc过程
- 更新系统没有mac dashboard 问题解决
- 一次由于开启 Safari 无痕浏览 引发的艰难“捉虫”事件
- python调用jar包类
- http请求方式和状态管理
- HDU 3265 Posters(线段树)
- JAVA 代理模式(Proxy)
- PDO--PHP Data Objects
- android ble蓝牙开发略解
- char与byte差异
- ajax格式,需要指定交互的data类型
- redis源码分析之事务Transaction(上)
- 初用MssqlOnLinux 【1】
- c++(八皇后)
- 在已有数据的表中添加id字段并且自增
- Bulb Switcher (leetcode java)
- SVG 使用marker画箭头(一)