pexpect ssh login and ls | grep
crybaby
joemystery123 at gmail.com
Tue Jan 1 12:51:15 EST 2008
I don't get 0 or 2(excuting ls command exit code)
from result.split('\r\n')[0] or result.split('\r\n')[1]. I have to
try another method.
Regular shell ssh login:
[joe at com1 ~]$ ssh my at mycomp2
Last login: Mon Dec 31 20:51:09 2007 from com1
[my at mycomp2 ~]$
Pexpect Login:
>>> import pexpect
>>> child=pexpect.spawn("ssh my at mycomp2")
>>> child.sendline("ls mytest.log > /dev/null 2>&1; echo $? ")
42
>>> child.expect([pexpect.TIMEOUT, r"\$"])
1
>>> result1=child.before
>>> result2=child.after
>>> print result1
Last login: Tue Jan 1 11:22:05 2008 from com1
[my at mycomp2 ~]
>>> print result2
$
>>> print result1.split('\r\n')[1]
[my at mycomp2 ~]
>>> print result1.split('\r\n')[0]
Last login: Tue Jan 1 11:22:05 2008 from com1
thanks.
More information about the Python-list
mailing list