我有一个可以登录到我的 Beaglebone 的预期脚本:
#!/usr/bin/expect -f
spawn ssh [email protected]
expect "[email protected]'s password:"
send "temppwd\r"
interact &&
mkdir emma &&
cd emma
这有效并且它登录到 debian 帐户。但是,当interact
其他两个命令未执行时,它会停止。我该怎么做才能做到这一点?
编辑
好的,谢谢 andy256 我觉得这interact
是错的,但是,我明白了
执行时命令名称“mkdir”无效
如何将 Expect 脚本与普通 Shell 脚本结合起来?
提前致谢 !
答案1
期望编程的主要内容是send
和expect
对:您向生成的进程发送一些文本并期望得到响应。在本例中,您发送 mkdir 命令,并期望看到提示符以知道命令已完成。提示符最好与正则表达式匹配,以匹配结尾因为提示符是可配置的,所以您可能需要编辑提示符表达式:该表达式匹配字符串末尾的文字美元符号和空格。
#!/usr/bin/expect -f
spawn ssh [email protected]
expect "[email protected]'s password:"
send "temppwd\r"
set prompt_re {\$ $}
expect -re $prompt_re
send "mkdir -p emma && cd emma\r"
expect -re $prompt_re
interact