成功ssh登录后,期望脚本不发送命令 [英] Expect script not sending commands after successful ssh login
问题描述
启动以下脚本时,ssh登录成功,并且我可以进行交互,但不发送cd folder
命令.如果我确定这是我要发送的第一个命令,并且我如何发送cd folder
命令,我的expect "$"
命令根本有用吗?
When launching the following script, the ssh login succeeds, and I'm able to interact, but it doesn't send the cd folder
command. Is my expect "$"
command useful at all if I know for sure that this is the first command I want to send, and how can the cd folder
command be sent?
这是期待已久的脚本:
#!/usr/bin/expect
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no host@exemple.com
expect "password"
send "mypassword\r"
expect "$"
send "cd folder\r"
interact
谢谢!
推荐答案
您需要expect
一个更具体的shell提示.
You need to expect
a more specific shell prompt.
根据期望的手册:
请注意,在许多编辑器中,
^
和$
分别与行的开头和结尾匹配.但是,由于Expect是不是面向行的,因此这些字符与期望匹配缓冲区中当前的数据的开始和结尾(相对于行)相匹配.
Note that in many editors, the
^
and$
match the beginning and end of lines respectively. However, because expect is not line oriented, these characters match the beginning and end of the data (as opposed to lines) currently in the expect matching buffer.
这篇关于成功ssh登录后,期望脚本不发送命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!