0

I need to issue "sudo service nginx status" to check for service status. I have the following:

import commands
service output = commands.getoutput("sudo service nginx status")

but I am getting "no tty present and no askpass program specified"

Does someone understand this?

1 Answer 1

1

using commands.getoutput makes impossible to provide the user input that is required by sudo command. The name is self explainable, you are interested only in the command output. stdin is closed.

There are several solutions for this:

  1. Turn off the password verification for the sudo user that is launching this python script. (read about /etc/sudoers)

  2. pipe your password: (unsafe/bad solution but easy) "echo YOURPASS | sudo ..."

  3. check out subprocess.popen allowing you to provide input either from console or from file https://docs.python.org/2/library/subprocess.html#popen-constructor

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.