Skip to content
Advertisement

“Cache” credentials on a bash script

I have created a bash script to run a few js scripts into MongoDB. Basically, what I am doing is, running the bash script and passing a parameter in this case called version, example:

JavaScript

That will go and execute all scripts for the version 1.0. Now, it is possible that MongoDB requires authentication user/pass, so I have an option in the script execution that will ask the user if it requires authentication.

JavaScript

My question is: what would be the best way to kind cache the same credentials to call the script multiple times? For example:

JavaScript

I don’t want to type in the same credentials every time the script runs.

Advertisement

Answer

Caio,

As stated in my comment here’s how I did it:
Thanks for Charles Duffy for the printf solution:

JavaScript

You can add these functions to your script. When you want to set the password ePass will do:

JavaScript

It will mask the input to avoid over-the-shoulder reading. Then it will echo the encoded output (remove after testing):

JavaScript

Then you dPass:

JavaScript

So when you call your mongo scripts you can use the dPass output as your arg.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement