how to issue sudo command using python -
i need issue "sudo service nginx status" check service status. have following:
import commands service output = commands.getoutput("sudo service nginx status") but getting "no tty present , no askpass program specified"
does understand this?
using commands.getoutput makes impossible provide user input required sudo command. name self explainable, interested in command output. stdin closed.
there several solutions this:
turn off password verification sudo user launching python script. (read /etc/sudoers)
pipe password: (unsafe/bad solution easy) "echo yourpass | sudo ..."
check out
subprocess.popenallowing provide input either console or file https://docs.python.org/2/library/subprocess.html#popen-constructor
Comments
Post a Comment