pexpect

pexpect - multiple expects

好久不见. 提交于 2020-01-24 12:13:25
问题 Is it possible to "wait" for different answers from an expect command at the same time? E.g: child.expect('first', 'second') And if YES, how can differentiate which one has triggered it? 回答1: Yes, you can do it like: i = child.expect(['first', 'second']) The expect() method returns the index of the pattern that was matched. So in your example: if i == 0: # do something with 'first' match else: # i == 1 # do something with 'second' match For more: http://pexpect.readthedocs.org/en/stable

pexpect - multiple expects

我是研究僧i 提交于 2020-01-24 12:13:12
问题 Is it possible to "wait" for different answers from an expect command at the same time? E.g: child.expect('first', 'second') And if YES, how can differentiate which one has triggered it? 回答1: Yes, you can do it like: i = child.expect(['first', 'second']) The expect() method returns the index of the pattern that was matched. So in your example: if i == 0: # do something with 'first' match else: # i == 1 # do something with 'second' match For more: http://pexpect.readthedocs.org/en/stable

Reading output of Top command using Paramiko

孤街醉人 提交于 2020-01-24 05:35:06
问题 I am writing a script in Python for login to ssh and read the output of commands just executed. I am using paramiko package for this. I am trying to execute command "top" and get its output printed on the console. However, I am not able to do this. Please find the snippet: import sys import time import select import paramiko host = 'localhost' i = 1 # # Try to connect to the host. # Retry a few times if it fails. # while True: print 'Trying to connect to %s (%i/30)' % (host, i) try: ssh =

Using pexpect to automate a manage.py syncdb dialogue

时间秒杀一切 提交于 2020-01-07 02:11:57
问题 I am trying to use pexpect to automate this dialogue. Also below is the python program using pexpect. When I run the code...it waits for input at "Would you like to create one now? (yes/no):" then timesout with an error. It is expecting a yes or no. So...where did I err? The string matches the first input? ubuntu@ip-10-142-73-169:/opt/graphite/webapp/graphite$ sudo python manage.py syncdb Creating tables ... Creating table account_profile Creating table account_variable Creating table account

Python PXSSH GUI spawn on login failure

廉价感情. 提交于 2020-01-04 14:03:41
问题 I can't stop the GUI from spawning when a login failure occurs. simple example that fails and spawns a GUI. >>> import pxssh >>> >>> ssh = pxssh.pxssh() >>> ssh.force_password = True >>> ssh.login('127.0.0.1', 'root', 'falsePW') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/pxssh.py", line 226, in login raise ExceptionPxssh ('password refused') pxssh.ExceptionPxssh: password refused >>> I have tried disabling x11 forwarding in

Python PXSSH GUI spawn on login failure

一曲冷凌霜 提交于 2020-01-04 14:03:10
问题 I can't stop the GUI from spawning when a login failure occurs. simple example that fails and spawns a GUI. >>> import pxssh >>> >>> ssh = pxssh.pxssh() >>> ssh.force_password = True >>> ssh.login('127.0.0.1', 'root', 'falsePW') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/pxssh.py", line 226, in login raise ExceptionPxssh ('password refused') pxssh.ExceptionPxssh: password refused >>> I have tried disabling x11 forwarding in

树莓派的媒体播放软件omxplayer

依然范特西╮ 提交于 2020-01-02 18:55:09
树莓派中的CPU性能较差,而GPU较强大。 omxplayer是专门针对树莓派的GPU的播放器。( made by Edgar (gimli) Hucek from the XBMC/Kodi project)该GPU(VideoCore)提供的官方API接口是OpenMAX。也就是说要想充分利用GPU来编程,其中一种途径是使用OpenMAX.但是,OpenMAX好像很难用。 树莓派上可以播放 H264 和 mp4 等视频格式,1080p也没问题,因为这种格式的文件有硬件加速。 首先安装 omxplayer ,这是一个命令行的播放器: sudo apt-get install omxplayer 然后就可以播放了,当然需要通过 HDMI 连接到显示器看: omxplayer -o hdmi /path/to/filename.mp4 -o hdmi 表示音频直接通过 HDMI 播放,播放时按左右箭头快进、按 q 退出。更多命令行选项和播放时的控制快捷键请参考 omxplayer 的文档:https://github.com/huceke/omxplayer 在文件管理里找到你要播放的视频。单击鼠标右键,选择打开方式。选择右边的自定义命令行。 在输入框里输入 omxplayer -o both %f 在下面一个框里输入一个名称作为打开文件的程序,再勾选如图所示的两个选项,确定。

fabric vs pexpect

让人想犯罪 __ 提交于 2020-01-01 01:53:14
问题 I've stumbled upon pexpect and my impression is that it looks roughly similar to fabric. I've tried to find some comparison, without success, so I'm asking here--in case someone has experience with both tools. Is my impression (that they are roughly equivalent) correct, or it's just how it looks on the surface ? 回答1: I've used both. Fabric is more high level than pexpect, and IMHO a lot better. It depends what you're using it for, but if your use is deployment and configuration of software

How do I capture Password prompt

一曲冷凌霜 提交于 2019-12-31 07:03:57
问题 I have the following code (updated to include pexpect): import sys import subprocess import pexpect print "0" ssh = subprocess.Popen("ssh -A -t username1@200.1.2.3 ssh -A -X username2@10.1.2.3", shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate() print "1" child = pexpect.spawn(ssh) print "2" child.expect ('password') print "3" child.sendline ('password2') print "4" result = ssh.stdout.readlines() if result == []: error = ssh.stderr.readlines() print >>sys.stderr,

Verify a file exists over ssh

可紊 提交于 2019-12-30 05:02:45
问题 I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below: def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpect.spawn('ssh service@10.10.0.0') i=p.expect([ssh_newkey,'password:',pexpect.EOF]) if i==0: p.sendline('yes') i=p.expect([ssh_newkey,'password:',pexpect.EOF]) if i==1: p.sendline("word") i=p