Python implementation of remote shell commands, error, and great guidance

#!/usr/bin/env python
import paramiko

hostname='XX'
username='XX'
password='XX'

if __name__=='__main__':
paramiko.util.log_to_file('paramiko.log')
s=paramiko.SSHClient()

s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname=hostname,username=username,password=password)

stdin,stdout,stderr=s.exec_command("sudo apt-get install remove redis-server")
stdin.flush()
print stdout.read()
print stderr.read()
s.close()

After my test, operation does not require the sudo command can be, but need the sudo command will prompt that sudo: no TTY present and no askpass program specified
,Who can help me to solve this problem, need to perform remote sudo commands in the script.

Started by Emerald at February 25, 2016 - 1:39 AM

Don't use this package, but to find a suggestion: (doubt not by what you say paramiko to go, the connection. )
  1. ssh.connect('127.0.0.1', username='jesse', password='lol')
  2. stdin, stdout, stderr = ssh.exec_command("sudo dmesg")
  3. stdin.write('lol\n')
  4. stdin.flush()
  5. data = stdout.read.splitlines()
  6. for line in data:
  7. if line.split(':')[0] == 'AirPort':
  8. print line

Posted by BCv at March 08, 2016 - 2:00 AM

Thanks to answer you, I took a careful look to your posts have information related to it, it is about according to paramiko module, but still can not solve the problem of what I said

Posted by Emerald at March 12, 2016 - 2:53 AM