远程登录linux主机更换IP地址【非交互】

#!/bin/bash#description: change ip on instances#Usage: ./ChangeIP.sh fileId vmId# flush the caches of remote hosts>~/.ssh/known_hosts#define the network configfile locationdist=/etc/sysconfig/network-scripts/ifcfg-eth0# define a function which copy the new ifcfg-eth0 file# from cloudstack management or from other host to new# instance boot from vm_fixip without interactivefunction scp_file(){expect -c “set timeout -1spawn -noecho scp $1 $2expect “yes/no”send \”yes\r\”expect “password:”send \”password\r\”expect eof”}scp_file ifcfg-eth0.$1root@vm$2:$dist# this function named res_new means restart network# on new instance loading from new network config file# without interactivefunction res_net(){expect -c “set timeout -1spawn -noecho ssh $1 $2expect “password:”send \”password\r\”expect eof”}res_net root@vm$2 “service network restart > /dev/null 2>&1 &”sleep 2exit 0

本文出自 “暗黑魔君腾云端” 博客,服务器空间,请务必保留此出处

,服务器空间,香港服务器租用即使爬到最高的山上,一次也只能脚踏实地地迈一步。

远程登录linux主机更换IP地址【非交互】

相关文章:

你感兴趣的文章:

标签云: