tcsh] jthimmai@musxoile24:~/jthimmai> cat monitor.py
import pexpect, sys
child = pexpect.spawn ('ssh -l jthimmai musxoile24')
i = child.expect (['Terminal type', '[#\:] '])
if i==0:
print'Login OK... need to send terminal type.'
child.sendline('vt100')
child.expect('[#\:] ')
elif i==1:
print'Login OK.'
print'Shell command prompt', child.after,child.before
child.sendline('uname -a')
#child.sendline('ls -lrt ')
child.expect('[#\:]')
print child.before
[Linux] [tcsh] jthimmai@musxoile24:~/jthimmai>
tcsh] jthimmai@musxoile24:~/jthimmai> /opt/python_2.7.2/bin/python monitor.py
Login OK.
Shell command prompt : Last login
Fri Mar 13 07
[Linux] [tcsh] jthimmai@musxoile24:~/jthimmai>
Tags:
如果您的“欢迎消息”与我的相同,那么它有冒号,并且您正在使用与冒号匹配的模式查找提示。你知道吗
这就是
child.before
打印Fri Mar 13 07
的原因,因为欢迎消息类似于:您可以更改if语句中的模式,以包含空格(如前所述)
这应该会有帮助。你知道吗
相关问题 更多 >
编程相关推荐