FAQ
Hi there!

I have a problem with a script that reads the contents of /etc/passwd from
a remote host. It doesn't always seem to read all lines:

<test.py>
#!/usr/bin/python

import os

for i in range(5):
pipe = os.popen("ssh -q root at remotehost cat /etc/passwd")
passwd = pipe.readlines()
pipe.close()
print len(passwd)
</test.py>

Here's the output:

969
72
969
325
969

If I enter the SSH command in a shell I always get all 969 lines of
/etc/passwd (the file does not change over time). Any clues?

I am using Python 2.1, OpenSSH 2.9p1 (client), OpenSSH 2.5.2p2 (server).

Regards
Carsten.

Search Discussions

  • David Bolen at Jul 3, 2001 at 11:16 pm

    Carsten Gaebler <clpy at snakefarm.org> writes:

    Hi there!

    I have a problem with a script that reads the contents of /etc/passwd from
    a remote host. It doesn't always seem to read all lines: (...)
    If I enter the SSH command in a shell I always get all 969 lines of
    /etc/passwd (the file does not change over time). Any clues?
    You might try also printing out the exit code of the child process
    (the result from your pipe.close() call) - perhaps the ssh is being
    interrupted or otherwise losing the connection?

    Another thought might be to try explicitly coding a readline() loop
    rather than the single call to readlines() to see if you notice any
    difference? Perhaps there's some interaction with readlines() and the
    pipe that makes it think it is done with data too early.

    --
    -- David
    --
    /-----------------------------------------------------------------------\
    \ David Bolen \ E-mail: db3l at fitlinxx.com /
    FitLinxx, Inc. \ Phone: (203) 708-5192 |
    / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
    \-----------------------------------------------------------------------/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 3, '01 at 4:19p
activeJul 3, '01 at 11:16p
posts2
users2
websitepython.org

2 users in discussion

David Bolen: 1 post Carsten Gaebler: 1 post

People

Translate

site design / logo © 2023 Grokbase