0

I am running Ubuntu 18.04 with bash and I would like to pass a password to a command that runs with sudo, but once its run, i.e the password is piped into the command (a python3 command to run an app), it asks for a passphrase twice, I am trying to do it via this:

echo "passphrase" | echo "passphrase" | echo $password | sudo command

but it doesn't seem to be working.

The output from the command is as follows:

sudo python3 app.py
Enter PEM pass phrase:
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on https://127.0.0.1:443/ (Press CTRL+C to quit)
 * Restarting with stat
Enter PEM pass phrase:
 * Debugger is active!
 * Debugger PIN: 157-564-730
127.0.0.1 - - [30/Jan/2019 18:29:44] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /static/style.css HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /static/vendor/bootstrap/css/bootstrap.css HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /static/css/simple-sidebar.css HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /static/vendor/jquery/jquery.min.js HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /static/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 200 -
127.0.0.1 - - [30/Jan/2019 18:29:45] "GET /favicon.ico HTTP/1.1" 404 -

Does anyone have any ideas how can I go about doing this via a unix command inside a bash script?

  • I'll edit it, thanks. The command is running a localhost app with sudo, the password part works, but the passphrase doesn't. – QPTR Jan 30 at 23:47
  • 1
    echo is no cat; the second echo will simply ignore any input from from the first. You could try { echo p1; echo p2; echo p3; } | command or printf '%s\n' p1 p2 p3 | command, but there's no telling if command will accept passwords simply from stdin, and not try to open the controlling terminal for that. – mosvy Jan 30 at 23:50
  • @mosvy Thanks for the answer. It seems like when I run both of those commands, the p3 is being accepted as my sudo password but the others are being ignored. – QPTR Jan 30 at 23:54
  • 1
    Yes, like @mosvy implies, the "localhost app" probably just doesn't accept passwords from stdin. You'll probably have to look up the docs for this program. Sometimes you can read passwords from a file, or embed a command that produces the output, e.g. python -m keyring get foo bar. – Sparhawk Jan 31 at 0:06
  • 5
    The standard way to automatize such things in Unix is with expect. – mosvy Jan 31 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.