您的位置:首页 > 运维架构

自动化运维,远程交互从服务器A上ssh到服务器B上,然后执行服务器B上的命令。

2015-02-04 15:15 387 查看
第一种:

ftp-v-n192.168.0.121<<!
userftpftp123
bay
!


第二种:

{
echo-e"\n"
echo-e"ifconfig"
}|telnet01234


第三种:

ssh192.168.0.2'/etc/init.d/httpdstart'


第一种方式最麻烦,比较喜欢第二种,第三种方式最简单,你觉得呢?

如果觉得好就收藏吧!如果还有其他方式,请留言告诉我,谢谢。

第四种:

#!/usr/bin/expect-f
setport22
setuserroot
sethost192.168.0.1
setpasswordroot
spawnssh-D$port$user@$host
#root@192.168.0.1'spassword:
expect"*assword:*"
send"$password\n"
spawnifconfig
interact
expecteof


send:用于向进程发送字符串
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互

第四种交互方式怎么样?如何从服务器A上ssh到服务器B上,然后执行服务器B上的命令?听起来是不是很海派呢!
案例:(获取服务器Bifconfig保存文件,scp到服务器A)


#!/usr/bin/expect-f
setport22
setuserroot
sethost192.168.1.2
setpasswordroot
settimeout-1
spawnssh$user@$host
expect{
"*yes/no"{send"yes\r";exp_continue}
"*assword:"{send"$password\r"}
}
expect"*#*"
send"ifconfig>/home/cfg\r"
send"exit\r"
interact
spawnscp$host:/home/cfg./
expect{
"*yes/no"{send"yes\r";exp_continue}
"*assword:"{send"$password\r"}
}
expecteof


第五种:

sshpass-prootssh192.168.48.73"w"


但需要安装sshpass

下载:sshpass-1.05.tar.gz

百度去吧。


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: