Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • popen and password entry

    7 answers - 745 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    hello,
    i want to use rsync for remote file transfer via popen, but couldnt pass the
    Password yet.
    here`s what i did
    cmd = 'rsync -av config root (AT) 10 (DOT) 1.1.1:/tmp/.'
    f = os.popen(cmd,'w')
    f.write('1234')
    #not worked
    f.write('1234\n')
    #not worked
    every time i see "Password:" line, then i tried popen2
    st_out, st_in = popen2.popen2(cmd)
    st_in.write('1234')
    #not worked
    st_in.write('1234\n')
    #not worked again
    i got bored to see "Password:" line every time and did st_out.close() to not
    to see stdout messages from rsync, but even this did not work.
    also i tried popen3() function same way.
    what should i do?
    Thanks.
  • No.1 | | 902 bytes | |

    hi,
    i have found expect method for this purpose. i`m trying to use pexpect but
    following code gives me an something strange as a result.
    # The CDE
    import pexpect
    cmd = '/usr/bin/rsync config root (AT) 10 (DOT) 1.1.2:/tmp/.'
    #cmd = 'ssh root (AT) 10 (DOT) 1.1.2'
    child = pexpect.spawn(cmd)
    passwd = 'qwe123'
    try:
    i = child.expect(['Password:','Password: ',pexpect.EF,
    pexpect.TIMEUT])
    if i == 0: child.sendline(passwd)
    elif i == 1: print 1
    elif i == 2: print 2
    elif i == 3: print 3
    except EF: print 'EF'
    except TIMEUT: print 'TIMEUT'
    print 'finished'

    # The result
    finished
    Exception pexpect.ExceptionPexpect: <pexpect.ExceptionPexpect instance at
    0xb7dfab2cin <bound method spawndel__ of <pexpect.spawn instance at
    0xb7db3a2c>ignored
  • No.2 | | 585 bytes | |

    Sinan Nalkaya <orome.the.valar (AT) gmail (DOT) comwrites:

    hi,
    i have found expect method for this purpose. i`m trying to use pexpect but
    following code gives me an something strange as a result.

    When working with pexpect, logging the entire conversation is extremely
    useful fro debugging

    import pexpect
    cmd = '/usr/bin/rsync config root (AT) 10 (DOT) 1.1.2:/tmp/.'
    #cmd = 'ssh root (AT) 10 (DOT) 1.1.2'
    child = pexpect.spawn(cmd)

    Add "child.logfile = sys.stdout" here and check what's going on.

    Ganesan
  • No.3 | | 496 bytes | |

    thanks for reply, i add the line you suggested, thats what i get

    sinan@sinan:~/tmp/multi_server$ python deneme.py
    Password: qwe123
    finished
    Exception pexpect.ExceptionPexpect: <pexpect.ExceptionPexpect instance at
    0xb7e0cb2cin <bound method spawndel__ of <pexpect.spawn instance at
    0xb7dc5a2c>ignored

    does rsync may cause a problem while trying to fork-exec ssh ?

    Add "child.logfile = sys.stdout" here and check what's going on.

    Ganesan
  • No.4 | | 355 bytes | |

    sinan nalkaya <orome.the.valar (AT) gmail (DOT) comwrites:

    thanks for reply, i add the line you suggested, thats what i get
    sinan@sinan:~/tmp/multi_server$ python deneme.py
    Password: qwe123
    finished

    Ah, got it. You didn't wait for the rsync process to complete. Put the body
    of the "try:" in a while loop.

    Ganesan
  • No.5 | | 597 bytes | |

    finally following code works,

    import pexpect, sys
    cmd = '/usr/bin/rsync config root (AT) 10 (DOT) 1.1.2:/tmp/.'
    #cmd = 'ssh root (AT) 10 (DOT) 1.1.2'
    child = pexpect.spawn(cmd)
    child.logfile = sys.stdout
    passwd = 'qwe123'
    i = 0
    try:
    while i == 0:
    i =
    child.expect(['Password:','Password: ',pexpect.EF,pexpect.TIMEUT])
    if i == 0: child.sendline(passwd)
    elif i == 1: print 1
    elif i == 2: print 2
    elif i == 3: print 3
    except EF: print 'EF'
    except TIMEUT: print 'TIMEUT'
  • No.6 | | 456 bytes | |

    i put while True: before top of line, i=child.expect() . it worked, the file
    has gone but also it goes into loop with many EF result, i tried the
    os.waitpid() function with child.pid but didnt help me. still couldn`t get
    the problem.
    thanks for help

    Thursday 15 June 2006 12:04, Ganesan Rajagopal wrote:
    Ah, got it. You didn't wait for the rsync process to complete. Put the body
    of the "try:" in a while loop.

    Ganesan
  • No.7 | | 427 bytes | |

    sinan nalkaya <orome.the.valar (AT) gmail (DOT) comwrites:

    child.expect(['Password:','Password: ',pexpect.EF,pexpect.TIMEUT])
    if i == 0: child.sendline(passwd)
    elif i == 1: print 1
    elif i == 2: print 2
    elif i == 3: print 3

    You don't need the second pattern, the first pattern will catch the second
    case also. You also need to break when i == 2 or i == 3.

    Ganesan

Re: popen and password entry


max 4000 letters.
Your nickname that display:
In order to stop the spam: 3 + 3 =
QUESTION ON "Development"

EMSDN.COM