Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    60

    Question ssh script


    Hi,

    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)
    time.sleep(50)
    child = pexpect.spawn ('ssh david@192.168.0.14')
    child.expect ('password:')
    child.sendline ('mypass')
    child.expect ('$')
    child.sendline ('df |nc 192.168.0.14 2222')
    child.sendline ('exit')
    child.sendline ('exit')
    However each time I get 0byte files logged.
    eg
    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 192.168.0.14 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

    David

  2. #2
    Just Joined!
    Join Date
    Jun 2008
    Posts
    60
    oopss, theres a typo.
    child.sendline ('df |nc 192.168.0.18 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
  •