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

Discussion in 'Python' started by Jaiky, Mar 1, 2013.

  1. Jaiky

    Jaiky Guest

    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
     
    Jaiky, Mar 1, 2013
    #1
    1. Advertising

  2. Jaiky

    Roy Smith Guest

    In article <>,
    Jaiky <> wrote:

    [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)?
     
    Roy Smith, Mar 1, 2013
    #2
    1. Advertising

  3. Jaiky

    Guest

    On Fri, Mar 1, 2013, at 09:24 AM, Roy Smith wrote:
    > In article <>,
    > Jaiky <> wrote:
    >
    > [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?)?
     
    , Mar 1, 2013
    #3
  4. Jaiky

    Jaiky Guest

    it is running in view..........
     
    Jaiky, Mar 1, 2013
    #4
  5. Jaiky

    Jaiky Guest

    it is running in view..........
     
    Jaiky, Mar 1, 2013
    #5
  6. Jaiky

    Jaiky Guest

    in django inviroment..............
     
    Jaiky, Mar 1, 2013
    #6
  7. Jaiky

    Jaiky Guest

    in django inviroment..............
     
    Jaiky, Mar 1, 2013
    #7
  8. On 01/03/2013 16:23, Jaiky wrote:
    > it is running in view..........
    >


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

    --
    Cheers.

    Mark Lawrence
     
    Mark Lawrence, Mar 1, 2013
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EO
    Replies:
    4
    Views:
    440
    MWells
    Jan 26, 2005
  2. Bald Purp

    Any good reason not to use Flash?

    Bald Purp, Jan 6, 2006, in forum: HTML
    Replies:
    91
    Views:
    2,079
    Travis Newbury
    Jan 16, 2006
  3. John Posner

    Question on Django and Django Book

    John Posner, Nov 13, 2010, in forum: Python
    Replies:
    0
    Views:
    329
    John Posner
    Nov 13, 2010
  4. eGenix Team: M.-A. Lemburg
    Replies:
    0
    Views:
    147
    eGenix Team: M.-A. Lemburg
    Jun 18, 2013
  5. Gary Roach
    Replies:
    0
    Views:
    144
    Gary Roach
    Jan 2, 2014
Loading...

Share This Page