0

I am running a particular mongo command which is not hiding the password in ps for some reason. Upon checking the mongo community they are asking us to hide the password on ps by sending the password as an input via echo command

Example

echo mypassword | usr/bin/mongostat --quiet -u readonly --authenticationDatabase admin

Now this works fine as long as the echo password is used at the start of the mongostat command, but the problem comes in when I store this entire value as a string in a variable

password="pass@123"
mongo_command="echo $password | usr/bin/mongostat --quiet -u readonly --authenticationDatabase admin"
$mongo_command

So when I execute the above script the output is coming as follows

pass@123 | /usr/bin/mongostat --quiet -u readonly --authenticationDatabase admin

It is ignoring the echo keyword and only sending the password when the $mongo_command is executed. So how can I avoid this and ensure that echo goes along with the password, then followed by the pipe (|) symbol to the mongo command so that it looks as shown below

echo Csco@123 | /usr/bin/mongostat --quiet -u readonly --authenticationDatabase admin
Enter password:
insert query update delete getmore command flushes mapped vsize  res faults qrw arw net_in net_out conn   set repl                time

Thanks

Zorrom
  • 1
  • 1
  • The stored cmd-line is being echoed, including the pipe. Try `eval $mongo_command`. btw - the first two `usr/bin/mongostat` are missing a leading `/` – Milag Oct 21 '20 at 13:14
  • Hi @Milag , the first two mongostat commands have a type mistake. Yes, I tried eval as following mongo_command="eval echo $password | usr/bin/mongostat --quiet -u readonly --authenticationDatabase admin $mongo_command After this it worked and thank you very much. Could you please let me know what this eval naturally does. I checked online about this, but couldnt understand it completely. Thanks once again – Zorrom Oct 27 '20 at 06:45
  • See the Q&A at this [link](https://stackoverflow.com/q/11065077/10304821) – Milag Oct 27 '20 at 12:26
  • @Milag Thank you once again :) – Zorrom Oct 27 '20 at 13:18

0 Answers0