简体   繁体   English

如何在 bash 脚本中执行 mongodb 命令

[英]How to execute mongodb commands inside the bash script

I'm trying to run mongo commands through my bash script file.我正在尝试通过我的 bash 脚本文件运行 mongo 命令。

I have sample.sh -- run with./sample.sh我有 sample.sh -- 与./sample.sh 一起运行

I want to run below command inside my sample.sh file.我想在我的 sample.sh 文件中运行以下命令。 It is bash script.它是 bash 脚本。 I want to mongo commands run inside the file, not inside the shell.我想在文件内部运行 mongo 命令,而不是在 shell 内部运行。

kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})

I get the error below:我收到以下错误:

./generate-service-dbs.sh: line 37: syntax error near unexpected token `('
./generate-service-dbs.sh: line 37: `kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})'


Don't you have to run command with --eval ?您不必使用--eval运行命令吗?

kubectl exec $mongoPodName -c mongo-mongodb -- mongo --eval 'db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM