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 ...
随机推荐
- php建立MySQL数据表
<?php $connect = mysql_connect("127.0.0.1","root",""); mysql_select ...
- LA 3027 合作网络 并查集
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- vim编辑器使用相关
alias 查看vi是否已经绑定vim 一.vim的块选择 v 字符选择 V 行选择 ctrl+v 快选择 y 复制选择的地方(p进行粘贴) d 删除选择的地方 二.vim多文件编辑 :n 编辑下一个 ...
- 在HTML标签<a/>中调用javascript代码
<a/>标签的“href”属性可以是一个有效的URL,表示跳转的目的地,除此之外,href还可以是一段javascript代码.当为“href”设置javascript代码时,格式如下:& ...
- Spring源码学习之:@async 方法上添加该注解实现异步调用的原理
在我们使用spring框架的过程中,在很多时候我们会使用@async注解来异步执行某一些方法,提高系统的执行效率.今天我们来探讨下 spring 是如何完成这个功能的. spring 在扫描be ...
- Following a Select Statement Through Postgres Internals
This is the third of a series of posts based on a presentation I did at the Barcelona Ruby Conferenc ...
- ASP.NET MVC : Action过滤器(Filtering)
http://www.cnblogs.com/QLeelulu/archive/2008/03/21/1117092.html ASP.NET MVC : Action过滤器(Filtering) 相 ...
- CSS 知识点
1:display:block:比较常用于<a><span>这两个标签——因为这两个标签非块元素,如果不用display:block定义一下,因为a标签没有结构,就是没有宽高, ...
- Squid代理服务器的安装与配置
一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用 ...
- Appium使用PageFactory初始化对象时报空指针错误
自己的测试框架里面,每个app页面都要初始化appium field,所以想到使用一个静态的变量,后来初始化一个页面对象时总是报空指针. 在网上找了好多材料,看着没有什么区别.后来在github上面看 ...