pexpect

No module named win32console, while running wexpect

泄露秘密 提交于 2019-12-11 09:27:41
问题 I want to run wexpect (the windows port of pexpect) on my Windows 7 64-bit machine. I am getting the following error: C:\Program Files (x86)\wexpect\build\lib>wexpect.py Traceback (most recent call last): File "C:\Program Files (x86)\wexpect\build\lib\wexpect.py", line 97, in <module> raise ImportError(str(e) + "This package was intended for Windows like operating systems.") ImportError: No module named win32console This package requires the win32 python packages.This package was intended for

Can I use fdpexpect on a file that's currently being written to?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 08:54:49
问题 I'm trying to wait until some text is written to a live logfile in Python. fdpexect would seem to be the right thing for this, but it isn't waiting. As soon as it hits the end of the file it terminates. I'm wondering if fdpexpect just doesn't support this and I'll need to work around it? The code I have is basically this: Creating the spawn object: # we're not using pexpect.spawn because we want # all the output to be written to the logfile in real time, # which spawn doesn't seem to support.

How do I get timestamps in logfile of pexpect

天大地大妈咪最大 提交于 2019-12-11 08:41:40
问题 I am using pexpect to handle my telnet and ssh communication. I am also writing all request/response in a logfile . using pexpect.logfile(filename) . I would like to have timestamps in the logfile as well. I can not find it anywhere in the documentation! Does anyone have any idea how to implement this functionality? 回答1: logfile can be any object that has write() , flush() methods: from datetime import datetime class TimestampedFile(object): def __init__(self, file): self.file = file def

looping over a some ips from a file in python?

我的未来我决定 提交于 2019-12-11 08:17:25
问题 I have got csv a file conatainning ips aranged in columns like : 10.38.227.233,VLAN-A,23 10.38.227.233,VLAN-XYZ,27 10.38.227.233,VLAN-XZ,27 10,38.169.103,VLAN-ABCD,11 10,38.169.103,VLAN-ABCD,16 10,38.169.103,VLAN-ABD,17 and so on for each ip i need to login to the cisco switch and execute some commands for ip 10.38.227.233(VLAN-A,23|VLAN-XYZ,27|VLAN-XZ,27) all the ips have the same password so i am trying to get the password prompt only once and loop over the ips from the file. I am a novice

pexpect telnet on windows

自古美人都是妖i 提交于 2019-12-11 07:32:16
问题 I've used pexpect on linux successfully to telnet/ssh into Cisco switches for CLI scrapping. I'm trying to convert this code over to Windows and having some issues since it doesn't support the pxpect.spawn() command. I read some online documentation and it suggested to use the pexpect.popen_spawn.PopenSpawn command. Can someone please point to me what I'm doing wrong here? I removed all my exception handling to simplify the code. Thanks. import pexpect from pexpect.popen_spawn import

Python Pexpect spawn object Flush

本秂侑毒 提交于 2019-12-11 06:01:08
问题 I have a script where i am creating a spawn object using pexpect. The code looks like this: self.rshcmd='rsh 192.X.X.X' self.pipe1 = pexpect.spawn(command=self.rshcmd, logfile=sys.stdout,maxread=512) Now after I get into this, I expect for prompt which I get is > And now I become su by sending su and then giving the password. Now my prompt as expected becomes # I have a router connected to this spawned PC (192.X.X.X) which is 192.168.1.1 I telnet into this router by sending telnet 192.168.1.1

How to see the output in pexpect?

旧巷老猫 提交于 2019-12-11 05:13:57
问题 I have write this program: [mik@mikypc ~]$ cat ftp.py #!/usr/bin/env python # This connects to the rediris ftp site # import pexpect child = pexpect.spawn('ftp ftp.rediris.es') child.expect('Name .*: ') child.sendline('anonymous') child.expect('ftp> ') child.sendline('noah@example.com') child.expect('ftp> ') child.sendline('lcd /tmp') child.expect('ftp> ') child.sendline('pwd') child.expect('ftp> ') child.sendline('bye') [mik@mikypc ~]$ ./ftp.py [mik@mikypc ~]$ [mik@mikypc ~]$ [mik@mikypc ~]$

pexpect send cursor movement

≯℡__Kan透↙ 提交于 2019-12-10 19:36:16
问题 How can you send cursor movements like the up,down,left,right keys with pexpect. The example below is to automate elinks which uses the up/down keys to select different links on a page. from pexpect import spawn child = spawn('elinks http://python.org') #what goes here to send down key child.interact() 回答1: How about using escape sequence for up(^[[A) or down(^[[B) like this. child.send("\033[A") # up child.send("\033[B") # down 回答2: The below script has the codes for all the four cursor

pexpect and ssh: how to format a string of commands after su - root -c

霸气de小男生 提交于 2019-12-10 10:13:30
问题 I am trying to iterate through a list of servers & passwords to change the sshd configs on a group of servers so that I can login/run commands via root using passwordless SSH keys. I can do this easily in bash but I'm trying to learn Python and (obviously) would like to forego entering in passwords manually. Here's the bash of what I want to do: scp ~/.ssh/id_rsa.pub /etc/ssh/sshd_config USER@IP:/tmp/ ssh -o StrictHostKeyChecking=no -t USER@IP "su - root -c \"chown root:root /tmp/id_rsa.pub;

Python学习笔记—自动化部署【新手必学】

一个人想着一个人 提交于 2019-12-09 22:15:01
前言 本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。 作者:唯恋殊雨 目录 pexpect fabric pexpect Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块。 Pexpect 的使用范围很广,可以用来实现与 ssh、ftp 、telnet 等程序的自动交互;可以用来自动复制软件安装包并在不同机器自动安装;还可以用来实现软件测试中与命令行交互的自动化。当然如果你还没学到自动化,建议可以先去小编的Python交流.裙 :一久武其而而流一思(数字的谐音)转换下可以找到了,里面有最新Python教程项目,多交流进步更快 import pexpect import sys child = pexpect.spawn('ssh std20@123.57.211.212') child.logfile = sys.stdout #fout = file('mylog.txt', 'w') #child.logfile = fout child.expect('password:') child.sendline('std20') child.expect('std20