shell-自动更改LINUX服务器IP
#!/bin/bash
echo "Enter the old ip:"$
echo "Enter the new ip:"$ if [[ $ == "" ]];then
echo "Usage: $0 Enter the new ip:$1"
echo "Usage: $0 Enter the old ip:$2"
exit
fi i=
for line in `ls /etc/sysconfig/network-scripts | grep -E "ifcfg-em|ifcfg-eth"`
do
strip=`cat /etc/sysconfig/network-scripts/$line | grep -i "$1"`
strboot=`cat /etc/sysconfig/network-scripts/$line | grep -i "^onboot" | awk -F '=' '{print $2}' | grep -i "yes"`
if [ -n "$strip" -a -n "$strboot" ];then
echo $line
file=$line
echo $strip
echo $strboot
ipfile="/etc/sysconfig/network-scripts/$file"
hostnamefile="/etc/sysconfig/network"
sed -i 's/^IPADDR/#IPADDR/g' $ipfile
#sed -i 's/^NETMASK/#NETMASK/g' $ipfile
sed -i 's/^GATEWAY/#GATEWAY/g' $ipfile
sed -i 's/^HOSTNAME/#HOSTNAME/g' $ipfile
sed -i 's/^HOSTNAME/#HOSTNAME/g' $hostnamefile
newip=$
newgateway=
newhostname=
cat >>$ipfile<<EOF
IPADDR="$newip"
GATEWAY="$newgateway"
EOF
echo "HOSTNAME=\"$newhostname\"" >>$hostnamefile
hostname "$newhostname"
echo "OK"
else
echo $line
echo $strip
echo $strboot
echo "error"
fi
done
shell-自动更改LINUX服务器IP的更多相关文章
- [zz] 使用ssh公钥密钥自动登陆linux服务器
目录 .生成密匙对 .拷贝公匙到远程机 .启动登陆代理 这种方法处理后每次需要运行命令:ssh-add ~/.ssh/id_dsa 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远 ...
- 使用ssh公钥密钥自动登陆linux服务器
转自:http://7056824.blog.51cto.com/69854/403669 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远程操作是每天工作的一部分.但随着服务器的 ...
- Windows 通过批处理自动执行 linux服务器上面命令的办法
1. 使用putty 下载地址 https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 直接使用 exe版本就可以 https:/ ...
- 利用七牛存储7天远程自动备份LINUX服务器
受服务器空间制约,我们不可能在VPS上每天都备份一份新的网站数据,一是没必要,二是占空间.我们折中一下,采用星期命名,每次备份将覆盖上星期同一天的文件.从而只备份7份数据,不至于占用特别大的空间. 如 ...
- java 获取服务器 linux 服务器IP 信息
public String getUnixLocalIp() { String ip = ""; try { Enumeration<?> e1 = (Enumerat ...
- shell:实现linux服务器资源监控并发送告警邮件
1.安装方式 wget http://10.8.225.126/wsmonitor/install.sh;sh install.sh test@test.com 2.install.sh #!/bin ...
- 通过shell脚本进行linux服务器的CPU和内存压测
文章目录 内存压测 python的方式 shell的方式 cpu压测 在正常手段下,这个只是压测的方法 在不正常手段下(crontab计划任务),可以提高CPU和内存的使用率 什么?你问我为什么要提高 ...
- CentOS 通过shell脚本过滤得到服务器IP地址
1.CentOS 6.x (32Bit &&64Bit) [root@localhost ~]# ifconfig |grep Bcast |awk '{print$2}' |sed ...
- [Linux][Mac]如何使用SSH登陆远程Linux服务器&使用SCP下载远程终端文件
--------------------------- 2017-01-16 初版 2017-01-17 增加ssh登录端口修改 -------------------------- 一.使用ssh ...
随机推荐
- img标签中alt和title属性的正确使用
在的img标签有两个属性分别为alt和title,对于很多初学者而言对这两个属性的正确使用都还抱有迷惑,当然这其中一部分原因也是ie浏览器所导致的.正确的使用这两个属性除了可以提高图片的搜索能力外,在 ...
- mm/mmap.c
/* * linux/mm/mmap.c * * Written by obz. */#include <linux/stat.h>#include <linux/sched. ...
- android之OptionMenu
一.现在我给大家介绍两个不同版本的模拟器(2.3.3和4.0.3) 1.布局文件 (1)打开“res/layout/activity_main.xml”文件. 先看mian布局文件 <Relat ...
- AutoFac使用~IOC容器(DIP,IOC,DI)
#cnblogs_post_body h1 { background-color: #A5A5A5; color: white; padding: 5px } Autofac一款IOC容器,据说比Sp ...
- List remove注意点
public class ListTest { public static void main(String[] args) { // TODO Auto-generated method stub ...
- Alpha版本——Postmortem会议
No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 设想和目标 1.我们的软件要解决什么 ...
- Openstack Neutron OVS ARP Responder
ARP – Why do we need it? In any environment, be it the physical data-center, your home, or a virtual ...
- ES6 Set和Map
一.Set遍历方法: set.key() set.values() set.entries() 二.Set例子: var s = new Set(); var arr = [1,1,2,3,6,8,8 ...
- Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据
背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...
- 一篇关于SpringMVC 传统文件上传的方法
一.界面效果 二.html代码 <legend>上传APK文件</legend> <form action="<%=basePath%>/apks/ ...