使用 #!/usr/bin/expect 和 bash
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21997554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using #!/usr/bin/expect and bash
提问by Frank Anthony
Is there any way I can use bash script along with /usr/bin/expect commands?
有什么方法可以将 bash 脚本与 /usr/bin/expect 命令一起使用吗?
Could I, for instance, use an if statement in a usr/bin/expect script?
例如,我可以在 usr/bin/expect 脚本中使用 if 语句吗?
回答by Timmah
Here is a very simple script that connects to a server via ssh from bash:
这是一个非常简单的脚本,它通过 bash 中的 ssh 连接到服务器:
#!/bin/bash
/usr/bin/expect <<EOF
spawn ssh user@server
expect {
"assword:" {
send -- "1234\r"
}
}
EOF
回答by Beano
expect
is an extension of tcl
- therefore you can use the programming constructs of tcl
- these include 'if'.
expect
是tcl
- 因此您可以使用tcl
- 这些包括'if'的编程结构的扩展。
Tcl command man pages are available: tcl.tk/man/tcl8.5/TclCmd/contents.htm
Tcl 命令手册页可用:tcl.tk/man/tcl8.5/TclCmd/contents.htm