Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

python ssh and sudo remote commands

Status
Not open for further replies.

subok

MIS
Feb 21, 2005
37
BE
Hi,
I was wondering if somebody can help.
I'm writing a python script to make a remote command but requires a sudo password. I got the following script but the password is not sendout it seems

thanks in advance for any assistance

Code:
import paramiko
import SocketServer
import socket
import commands
import os
import time

ssh=paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect ('127.0.0.1','22','user','password')
chan = ssh.invoke_shell()
chan = ssh.get_transport().open_session()
chan.get_pty()
chan.exec_command('sudo ls /qp1/mo/script >>/home/user/dirout.test')
print(chan.recv(4096))
chan.send('password\n')
ssh.close()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top