pxssh submit su commands = very very slow

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gert

    pxssh submit su commands = very very slow

    This works but after the su command you have to wait like 2 minutes
    before each command gets executed ?
    What did i do wrong ?

    import pxssh

    try:
    s = pxssh.pxssh()
    s.login ('127.0.0.1', 'gert', '123')
    s.sendline ('uptime')
    s.prompt()
    print s.before
    s.sendline ('ls -l')
    s.prompt()
    print s.before
    s.sendline ('df')
    s.prompt()
    print s.before
    s.sendline ('su')
    s.expect('Passw ord:')
    s.sendline ('123')
    s.prompt()
    print s.before
    s.sendline ('df')
    s.prompt()
    print s.before
    s.sendline ('exit')
    s.logout()

    except pxssh.Exception Pxssh, e:
    print "pxssh failed on login."
    print str(e)
  • Neil Hodgson

    #2
    Re: pxssh submit su commands = very very slow

    gert:
    This works but after the su command you have to wait like 2 minutes
    before each command gets executed ?
    s.sendline ('su')
    s.expect('Passw ord:')
    A common idiom seems to be to omit the start of the expected reply
    since it may not be grabbed quickly enough. Then the prompt has to time
    out. Try
    s.expect('asswo rd:')

    Neil

    Comment

    • gert

      #3
      Re: pxssh submit su commands = very very slow

      On Jun 29, 1:19 am, Neil Hodgson <nyamatongwe+th un...@gmail.com >
      wrote:
      gert:
      >
      This works but after the su command you have to wait like 2 minutes
      before each command gets executed ?
                  s.sendline ('su')
                  s.expect('Passw ord:')
      >
          A common idiom seems to be to omit the start of the expected reply
      since it may not be grabbed quickly enough. Then the prompt has to time
      out. Try
                    s.expect('asswo rd:')
      >
      I tested, but it has the same result. Each command after the su
      command needs 2 minutes before pxssh display's its output.
      Could there be a expat loop in pxssh or something ?

      Comment

      • gert

        #4
        Re: pxssh submit su commands = very very slow

        On Jun 29, 1:44 am, gert <gert.cuyk...@g mail.comwrote:
        On Jun 29, 1:19 am, Neil Hodgson <nyamatongwe+th un...@gmail.com >
        wrote:
        >
        gert:
        >
        This works but after the su command you have to wait like 2 minutes
        before each command gets executed ?
                    s.sendline ('su')
                    s.expect('Passw ord:')
        >
            A common idiom seems to be to omit the start of the expected reply
        since it may not be grabbed quickly enough. Then the prompt has to time
        out. Try
                      s.expect('asswo rd:')
        >
        I tested, but it has the same result. Each command after the su
        command needs 2 minutes before pxssh display's its output.
        Could there be a expat loop in pxssh or something ?
        I am pretty sure it has to do with the prompt changing from $ to #

        Comment

        • Grant Edwards

          #5
          Re: pxssh submit su commands = very very slow

          On 2008-06-28, Neil Hodgson <nyamatongwe+th under@gmail.com wrote:
          gert:
          >This works but after the su command you have to wait like 2 minutes
          >before each command gets executed ?
          > s.sendline ('su')
          > s.expect('Passw ord:')
          >
          A common idiom seems to be to omit the start of the
          expected reply since it may not be grabbed quickly enough.
          Then the prompt has to time out. Try s.expect('asswo rd:')
          I don't see why the first letter of the password prompt would
          be dropped. Tty drivers have buffered data for as long as I've
          been using Unix (25+ years). After writing the username you
          can wait for an hour before calling read(), and you'll still
          see the entire password prompt. I always assumed it was done
          that way so the script would work for either "password:" or
          "Password:" .

          --
          Grant Edwards grante Yow! Edwin Meese made me
          at wear CORDOVANS!!
          visi.com

          Comment

          • gert

            #6
            Re: pxssh submit su commands = very very slow

            this does the same except 100 times faster ?

            I don't understand the logic about the prompt, its not the same as the
            output from the bash shell ?

            root@r12276:~# cat ssh2.py
            import pexpect
            import sys

            child = pexpect.spawn(" ssh gert@127.0.0.1" )
            #child.logfile = sys.stdout

            i = child.expect(['assword:', r'yes/no'],timeout=120)
            if i==0:
            child.sendline( '123')
            elif i==1:
            child.sendline( 'yes')
            child.expect('a ssword:', timeout=120)
            child.sendline( '123')
            child.expect('g ert@rxxxx.ovh.n et: ~')
            print child.before

            child.sendline( 'ls -l')
            child.expect('g ert@rxxxx.ovh.n et:')
            print child.before

            child.sendline( 'su')
            child.expect('a ssword:')
            child.sendline( '123')
            child.expect('g ert@rxxxx.ovh.n et: /srv/www/gert')
            print child.before

            child.sendline( 'ls -l')
            child.expect('r oot@rxxxx.ovh.n et:')
            print child.before

            Comment

            • Dan Stromberg

              #7
              Re: pxssh submit su commands = very very slow

              On Sat, 28 Jun 2008 19:08:59 -0700, gert wrote:
              this does the same except 100 times faster ?
              >
              I don't understand the logic about the prompt, its not the same as the
              output from the bash shell ?
              >
              root@r12276:~# cat ssh2.py
              import pexpect
              import sys
              >
              child = pexpect.spawn(" ssh gert@127.0.0.1" ) #child.logfile = sys.stdout
              >
              i = child.expect(['assword:', r'yes/no'],timeout=120) if i==0:
              child.sendline( '123')
              elif i==1:
              child.sendline( 'yes')
              child.expect('a ssword:', timeout=120) child.sendline( '123')
              child.expect('g ert@rxxxx.ovh.n et: ~') print child.before
              >
              child.sendline( 'ls -l')
              child.expect('g ert@rxxxx.ovh.n et:')
              print child.before
              >
              child.sendline( 'su')
              child.expect('a ssword:')
              child.sendline( '123')
              child.expect('g ert@rxxxx.ovh.n et: /srv/www/gert') print child.before
              >
              child.sendline( 'ls -l')
              child.expect('r oot@rxxxx.ovh.n et:')
              print child.before
              You could try changing the prompt (pxssh appears to have a way of doing
              that), but I prefer to set up passwordless, passphraseless ssh and do
              each command separately. For the rootly portions, you might look into
              passwordless sudo if you go that route.

              Here's something about setting up passwordless, passphraseless ssh:



              Comment

              • gert

                #8
                Re: pxssh submit su commands = very very slow

                On Jun 29, 4:45 am, Dan Stromberg <dstrombergli.. .@gmail.comwrot e:
                On Sat, 28 Jun 2008 19:08:59 -0700, gert wrote:
                this does the same except 100 times faster ?
                >
                I don't understand the logic about the prompt, its not the same as the
                output from the bash shell ?
                >
                root@r12276:~# cat ssh2.py
                import pexpect
                import sys
                >
                child = pexpect.spawn(" ssh g...@127.0.0.1" ) #child.logfile = sys.stdout
                >
                i = child.expect(['assword:', r'yes/no'],timeout=120) if i==0:
                    child.sendline( '123')
                elif i==1:
                    child.sendline( 'yes')
                    child.expect('a ssword:', timeout=120) child.sendline( '123')
                child.expect('g ...@rxxxx.ovh.n et: ~') print child.before
                >
                child.sendline( 'ls -l')
                child.expect('g ...@rxxxx.ovh.n et:')
                print child.before
                >
                child.sendline( 'su')
                child.expect('a ssword:')
                child.sendline( '123')
                child.expect('g ...@rxxxx.ovh.n et: /srv/www/gert') print child.before
                >
                child.sendline( 'ls -l')
                child.expect('r ...@rxxxx.ovh.n et:')
                print child.before
                >
                You could try changing the prompt (pxssh appears to have a way of doing
                that), but I prefer to set up passwordless, passphraseless ssh and do
                each command separately.  For the rootly portions, you might look into
                passwordless sudo if you go that route.
                >
                Here's something about setting up passwordless, passphraseless ssh:
                >
                http://stromberg.dnsalias.org/~strombrg/ssh-keys.html
                My boss does not allow me to cp a key on the phone server. I only have
                a email with some commands and passwords.

                Comment

                Working...