Friday, March 1, 2013

Re: os.system() is not working in django while working on server centos

On Fri, Mar 1, 2013 at 11:29 AM, JAI PRAKASH SINGH
<jaiprakashsingh213@gmail.com> wrote:
> 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
>

This doesn't seem related to Django… try a python mailing list.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment