是否可以通过expect脚本执行以下操作?
我有Linux服务器连接到linux_machine1,linux_machine1连接到linux_machine2。
我的Linux服务器只能访问linux_machine1 ( linux服务器可以对linux_machine1进行远程访问,但不能将linux服务器传输到linux_machine2 )
但是从linux_machine1我可以通过telnet访问linux_machine2
所以我的问题是:
我需要开发从Linux服务器执行telnet到linux_machine1的expect脚本。
然后expect将从linux_machine2执行telnet到linux_machine1,并将/etc/host文件从linux_machine2复制到我的Linux服务器
这个场景可以由expect脚本实现吗?
描述这一过程的简短示例:
( run expect from Linux server ) --> linux_machine1 --> linux_machine2
Linux server <-- /etc/hosts from linux_machine2 <--发布于 2014-04-29 03:52:57
从Linux_Server运行下面的脚本。
不要使用telnet,因为它是未加密的。您可以使用ssh和sftp,如下所示。
#This part connects to Machine1
#Just change username, password_here and Linux_machine1 to suit your requirement.
#!/usr/bin/expect -f
spawn telnet -l username linux_machine1
expect "*?assword:*"
send -- "password_here\r"
send -- "\r"
expect eof
#Now we are connected to Linux_Machine1 from where we will connect to Linux_machine2
#Just change username, password_here and Linux_machine2 to suit your requirement.
spawn ftp username@machine2
expect "*?assword:*"
send -- "password_here\r"
send -- "\r"
expect eof
expect "ftp>"
send -- "get /etc/hosts\r"
expect "ftp>"
send "quit \r"在Linux_Server的本地文件夹中,将有一份/etc/hosts副本。
P.S:在本地机器上测试,工作非常好。如果您仍然希望使用telnet,上述脚本将给您一个如何做它的想法。您可以根据需要将ssh和sftp连接修改为telnet。
P.P.S:如果你能用砖块或恭维回复我,我会非常感激,因为我花了半个小时准备这个剧本:)好吧,不是半小时,但绝对是15分钟
https://unix.stackexchange.com/questions/127008
复制相似问题