SSH + here文档+互动模式 [英] ssh + here document + interactive mode
问题描述
我可以运行远程计算机上通过ssh立即文档脚本交互模式?
Can I run a here document script over ssh on remote machine with interactive mode?
code的例子是:
ssh -t xijing@ggzshop.com 'bash -s' <<EOF
sudo ls
......Other big scripts......
EOF
双-t将无法正常工作为好。
-----------------------------一个可能的解决方案:-------------- -----
double -t won't work properly as well.
-----------------------------One possible solution:-------------------
在很多的尝试,我想出了如下回答:
After a lot of tries, I come up with following answers:
Script=`cat <<'EOF'
sudo ls
.....Big scripts.....
EOF`
ssh -t user@host ${Script}
这将允许用户输入密码。
which will allow user to type password in.
推荐答案
西京的解决方案似乎为我工作正常。但是,我做了几个化妆品的变化。首先,为便于阅读我用美元括号,而不是反引号。对于另一件事我不提供任何解释:需要有分号来分隔在脚本多个命令片段,即使命令写在单独的行。我的测试:
Solution of Xijing appears to work ok for me. However, I did a couple of cosmetic changes. First, for readability I used "dollar-parentheses" instead of backticks. For another thing I don't offer any explanation: Semicolons were needed to separate multiple commands in Script snippet even though commands are written on separate lines. My test:
Script=$( cat <<'HERE'
hostname;
cat /etc/issue;
sudo id
HERE
)
ssh -t user@host ${Script}
须藤密码将在以正常的方式被询问,没必要省略
Sudo password will be asked in a normal manner, no need to omit that.
这篇关于SSH + here文档+互动模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!