小编Lib*_*t0r的帖子

在纯粹的bash中将密码传递给ssh

我想传递一个密码来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,然后直接发送一个字符串给它?

linux bash pipe

36
推荐指数
2
解决办法
12万
查看次数

MongoDB - 插入记录时转义引号

我在尝试编写 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 …

bash mongodb

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×2

linux ×1

mongodb ×1

pipe ×1