pexpect ssh login and ls | grep



I need to ssh into a remote machine and check if mytest.log file is
there. I have setup ssh keys to handle login authentications.

How do I determine if mytest.log is there by using Pexpect. What I
have done so far is spawned a child for ssh.

1) Now what do I do to execute shell_cmd(ls and grep), spawn another
child?

2) Can I use the same child that was spawned for ssh, if so how?

3) After executing the ls -l|grep mystest.log, how do I get the value
from pexpect?

shell_cmd = 'ls -l | grep mytest.log'
child = pexpect.spawn ('ssh my@mycomp2')
#child.sendline(shell_cmd)

child.sendline("ls")
3
print child.before
:~[
child.after
'my@mycomp2 '

child.sendline('/bin/bash', ['-c',shell_cmd])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sendline() takes at most 2 arguments (3 given)

thanks,
joe
.



Relevant Pages

  • Re: del behavior 2
    ... I have a script that uses child ... ptys to facilitate ssh connections. ... So if python does not get a chance to ... Perhaps the problem is that the master socket *doesn't* get closed? ...
    (comp.lang.python)
  • Re: del behavior 2
    ... interrupted and does not get a chance to clean everything up then what ... ptys to facilitate ssh connections. ... python process I am left with the child processes running and the ssh ... Perhaps the problem is that the master socket *doesn't* get closed? ...
    (comp.lang.python)
  • Re: pexpect ssh login and ls | grep
    ... I have setup ssh keys to handle login authentications. ... How do I determine if mytest.log is there by using Pexpect. ... have done so far is spawned a child for ssh. ... child.expect([pexpect.TIMEOUT, prompt]) ...
    (comp.lang.python)
  • Expect problems with SSH & Connect.c combo
    ... I've managed to get an Expect script running that signs into a host via ... with SSH and connect.c. ... parent: ... parent: now unsynchronized from child ...
    (comp.lang.tcl)
  • Executing remote commands via ssh causes zombie process
    ... I tried to execute the command "ls -l" using the ssh executable on the ... it's not relevant whether I use plink or ssh. ...
    (Debian-User)