我想传递一个密码来ssh
使用bash脚本(是的,我知道我可以使用ssh密钥,但这不是我想要的).
我找到了一些正在使用的解决方案,expect
但由于它不是标准的bash工具,我想知道我是否可以使用管道来做到这一点.
有人可以向我解释,为什么会这样:
echo "password\n" | ssh somehost.com
Run Code Online (Sandbox Code Playgroud)
要么
ssh somehost.com <(echo "password\n")
Run Code Online (Sandbox Code Playgroud)
不起作用?有没有可能使它工作?也许ssh
作为一个不同的进程执行,获取它的PID,然后直接发送一个字符串给它?
我在尝试编写 bash scritp 以将一些数据从一个数据库复制到另一个数据库时遇到了一个奇怪的问题。
为简单起见,我将通过以下示例展示该问题:
假设我们有一个文件,其中包含要在mongo client
. 有了Bash
这将是:
cat file.json | mongo --verbose --host $HOST
Run Code Online (Sandbox Code Playgroud)
这工作正常,直到我们在记录内容中使用 qoutes。
例如:
use somedb;
db["collection"].insert({ "field": "test" })
#This of course works
db["collection"].insert({ "field": "test \" test" })
#But this doesn't
db["collection"].insert({ "field": "test \\" test" }) "#<-For syntax coloring
#I thounght maybe double quoting will help, but this also doesn't work
db["collection"].insert({ "field": "\"test\"" })
#This SUPRISINGLY works!!!
Run Code Online (Sandbox Code Playgroud)
我的问题是,为 mongo 客户端(我正在使用MongoDB shell verions: 2.2.4
)转义报价的正确方法是什么?为什么当记录中有偶数个引号时,脚本会成功而奇数会失败?我会补充一点,没有错误消息。Mongo
只是无声地失败(即使使用--verbose …