os.system() not responding on django... any reason?


J

Jaiky

import sys,os
sys.stderr = open('/dev/null')
import paramiko
sys.stderr = sys.__stderr__

os.system("echo \'s3\' >> myfile.txt ") #debug first in ssh2
def ssh2_connect(host, user, pswd, port=22):
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, user, pswd)
return ssh
except Exception, e:
return str(e) + "Error. Failed to connect. Wrong IP/Username/Password"


def ssh2_exec(ssh, cmd, sudo=False):
result = []
try:
channel = ssh.get_transport().open_session()
if sudo:
channel.get_pty()
except:
return result

stdin = channel.makefile('wb')
stdout = channel.makefile('rb')

channel.exec_command(cmd)

exit_status = channel.recv_exit_status()

if exit_status == 0:
for line in stdout:
result.append(line)
channel.close()
return result


def ssh2_close(ssh):
ssh.close()
return


def ssh2_copyToFile(ssh, local_file, remote_file):
sftp = paramiko.SFTPClient.from_transport(ssh.get_transport())
sftp.put(local_file, remote_file)
return
 
Ad

Advertisements

R

Roy Smith

[a lot of code involving ssh and paramiko]

Here's a few general suggestions:

1) Try to reduce this to the smallest possible amount of code which
demonstrates the problem. You gave us a page full of complicated stuff.
Keep hacking away lines of code that don't change the behavior until you
get it down to something small and understandable.

2) Try to eliminate environmental problems. You're running this under
django? Does it work as a stand-alone process (i.e. without django)?
 
M

marduk

[a lot of code involving ssh and paramiko]

Here's a few general suggestions:

1) Try to reduce this to the smallest possible amount of code which
demonstrates the problem. You gave us a page full of complicated stuff.
Keep hacking away lines of code that don't change the behavior until you
get it down to something small and understandable.

2) Try to eliminate environmental problems. You're running this under
django? Does it work as a stand-alone process (i.e. without django)?


Also, what is the context (Is it running in a Django view; a model? a
signal handler? in settings?)?
 
Ad

Advertisements

Ad

Advertisements

M

Mark Lawrence

it is running in view..........

When replying can you please ensure we have the complete context,
otherwise we have to spend time looking, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top