From: Julian Schaefer-J. <jul...@t-...> - 2002-06-06 21:14:04
|
> I had problems with pyssh where it would have "winning streaks" where > it worked fine and "losing streaks" where it didn't. I tried very hard > to fix the problems, but was not successful. It looks as if I narrowed the problem. > > TheAddicT@siddhartha:~/swt-miles/proto/engine/ssh> python pyssh.py > > command="top -n 0" host=localhost password=<passwd> debug=1 > > > > >> child says: "TheAddicT@localhost's password: " > > >> child took 9 password bytes > > >> sleeping 0 secs > > >> child took 9 command bytes > > >> child response is 'lalalala\r\n\r\ntop -n 0\r\n' > > > > results = > > '<passwd>\r\n\r\ntop -n 0\r\n' ... was the correct output. And I managed to get a "connection refused" with the wrong password. So it seams as if the thing is working. It' s just not sending the output correct... After a little fiddling I came up with this to narrow the mistake: import os import pty import time passwd = "lalalala" + "\n" cmd = "uname -a" + "\n" pid, fd = pty.fork() if pid == 0: os.execv('/usr/bin/ssh', ['/usr/bin/ssh', 'localhost']) else: time.sleep(4) print os.read(fd, 1024) # prompt os.write(fd, passwd) # send password (NOTE: invisible) time.sleep(4) os.write(fd, cmd) # send command #print os.read(fd, 1024) # read echod command time.sleep(2) print os.read(fd, 1024) # read result os.write(fd, 'exit\n') print os.read(fd, 1024) And ... just as I expected the whole thing didn' t work like this. It behaves like my original script & your lib when I used it. It simply put out the command that I used. But when I remove the comment before the fifth-but-last line it works just fine. This must have something to do with some non-existing buffer-handling like "Read me now - course when you write something else I am gone". And since the ssh-client will echo the command itself it shall be read as well. At least that' s the little nonsense I make of it now... I'll experiment a little bit & try to determine via select if there is something to read. > I ultimately ended up using the non-phrase-protected public/private key > scheme to avoid the password/passphrase. > > You'll either have to do the same, or see if you can fix the code > yourself (I already tried). You might also check c.l.p. Perhaps someone > has made progress on this since the last time I asked around. This just in case you' re still interested in making the thingy work... If I come up with a permanent solution, respectively if I get to write some nifty code that "knows" when to read, I'll let you know... Greets & thanx for your answer. Julian. |