Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: ssh script

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question ssh script


    I have scripted this code to ssh into my remote server and log back some info.

    import sys, os, re, optparse, traceback, types, time, getpass
    import pexpect, pxssh
    import readline, atexit

    begin = time.time()
    os.system('nc -l 2222 > log%s &' %begin)
    child = pexpect.spawn ('ssh david@')
    child.expect ('password:')
    child.sendline ('mypass')
    child.expect ('$')
    child.sendline ('df |nc 2222')
    child.sendline ('exit')
    child.sendline ('exit')
    However each time I get 0byte files logged.
    0 Nov 3 11:15 log1288782916.15
    No when I do the same stuff manually:
    local machine

    nc -l 2222 > log &
    Then ssh into remote server & do
    df |nc 2222
    it works
    2880 Nov 3 11:27 log
    I do a strace on nc ( launched from script )
    shutdown(4, 0 /* receive */) = -1 ENOTCONN (Transport endpoint is not connected)
    Any thoughts guys?

    Thanks in advance


  2. #2
    oopss, theres a typo.
    child.sendline ('df |nc 2222').

    Back to my client machine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts