pexpect

How to get Fabric to automatically (instead of user-interactively) interact with shell commands? Combine with pexpect?

♀尐吖头ヾ 提交于 2019-12-28 05:28:45
问题 Seeking means to get Fabric to automatically (instead of user-interactively) interact with shell commands (and not just requests for passwords, but also requested user input when no "stdin/interactive override" like apt-get install -y is available). This question along with these Fabric docs suggest that Fabric can only "push the interactivity" back to the human user that's running the Fabric program. Seeking to instead fully automate without any human presence. Don't yet have a "real,"

基于脚本的服务器集群管理工具

别等时光非礼了梦想. 提交于 2019-12-24 14:09:54
基于脚本的服务器集群管理工具 背景: 随着云计算服务的普及,基于云计算的PaaS、IaaS受到越来越多的关注,使用这些服务的用户也越来越多。对于一些大型的应用而言,可能包含多种服务,而这些服务需要部署在多台服务器上。例如:某个应用可能部署了10台数据库服务器,10台Web Http服务器以及5台静态文件存储服务器等。那么作为应用程序管理员来说,一台一台地登录去管理这些机器显得非常繁琐,而且对于同一种服务(比如数据库服务)的机器需要执行的管理任务又都大致相同,那么对每台机器进行重复的工作也会增加集群管理员的负担。 应对上述需求场景,我开发了这样一个基于脚本的服务器集群管理工具,它主要具有如下功能和优点: 1、 针对不同应用场景,对服务器进行高效的分组管理。 2、 以可执行脚本作为子任务,可以自定义脚本内容,具有高度灵活性。以多个脚本组成的有序组序列作为可执行任务单元。脚本可分组,同组内可排序,有效组织和管理。 3、 针对不同需求,创建“服务器组<->脚本组”的执行任务。随时启动该任务,便可下达对该服务器组的基于脚本序列的任务执行命令。 4、 提供对“服务器组<->脚本组”的执行任务的运行状态查询,便于监控。可以查看远程服务器控制台的输出显示,当前运行状态,执行到哪个脚本,哪个脚本有异常等等信息。 应用场景举例: 假如我想为我的10台机器同时安装LAMP

Can't import pxssh from pexpect

断了今生、忘了曾经 提交于 2019-12-24 12:12:45
问题 i'm trying to import pxssh from pexpect. But i get the following error, and i dont know how to solve this. >>> from pexpect import pxssh Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self

print delay with pexpect: select returning stdin when no data ready to read

拥有回忆 提交于 2019-12-24 00:52:22
问题 Using pexpect I'm running Python in a subprocess. When the program below is run, I have to hit a key before the >>> prompt is displayed. I previously was using a naive version of pexpect, but switched hoping this would fix the problem. In this naive version, the problem was that select.select() returned stdin as ready to read when in fact it wasn't, as a blocking read on stdin was attempted, blocking the program until I hit a key. I suspect the same thing is happening here. How do I prevent

How to perform a root command with Pexpect?

喜欢而已 提交于 2019-12-23 18:31:43
问题 I'm working on a python program to assist with the apt-get tool. I want to use pexpect to download the chosen package. I believe I'm getting stuck at the child.expect line. It seems to timeout when it comes to that line. butt = "vlc" child = pexpect.spawn('sudo apt-get install ' + butt) child.logfile = sys.stdout child.expect('[sudo] password for user1: ') child.sendline('mypassword') This is the log file. TIMEOUT: Timeout exceeded. <pexpect.spawn object at 0xb5ec558c> version: 3.2 command:

pexpect - run script.sh over ssh

只愿长相守 提交于 2019-12-23 15:19:42
问题 I'm having trouble programmatically running a local script over ssh. I'm unsure if this is a problem with the shell variable substitution on the local host. When manually running, ssh monit@server1 'bash -s' < /u02/splunk/splunk/etc/apps/Splunk_TA_nix/bin/cpu.sh I get the expected output, CPU pctUser pctNice pctSystem pctIowait pctIdle all 11.21 0.00 1.50 0.31 86.98 0 0.00 0.00 0.00 0.00 100.00 1 3.00 0.00 1.00 0.00 96.00 .... but I get bash: /u02/splunk/splunk/etc/apps/Splunk_TA_nix/bin/cpu

python pexpect & pxssh with sudo and EOF

萝らか妹 提交于 2019-12-23 05:11:42
问题 I make ssh login with this script: import pxssh import pexpect s = pxssh.pxssh() hostname = 'localhost' username = 'py_worker' password = 'nicejob' s.login (hostname, username, password) print "logged in" Then I want to run some program which in some case may require sudo password and in some case may not require. So I want a scrip which could provide sudo password in those cases when required and just run the program if sudo is not asked. I thought this code could handle: s.sendline('sudo

How to create and use multiple pipes within the same process with pexpect?

我与影子孤独终老i 提交于 2019-12-22 14:46:51
问题 I'm trying to communicate with gdb asynchronously using pexpect. If I use the same pipe to do it, the commands sent using pexpect's sendline() function gets mixed into each other. And if I synchronize it like this: def send_command(str): global p with GDB_Engine.lock: p.sendline(str) p.expect_exact("(gdb)") It'll be too slow since there'll be tons of commands coming thru. So the thing I want to do is to implement different pipes for every send_command() block then close it when the work

How to create and use multiple pipes within the same process with pexpect?

点点圈 提交于 2019-12-22 14:46:06
问题 I'm trying to communicate with gdb asynchronously using pexpect. If I use the same pipe to do it, the commands sent using pexpect's sendline() function gets mixed into each other. And if I synchronize it like this: def send_command(str): global p with GDB_Engine.lock: p.sendline(str) p.expect_exact("(gdb)") It'll be too slow since there'll be tons of commands coming thru. So the thing I want to do is to implement different pipes for every send_command() block then close it when the work

Using expect() and interact() simultaneously in pexpect

狂风中的少年 提交于 2019-12-21 06:29:27
问题 The general problem is, that I want to use pexpect to call scripts that require sudo rights, but I don't always want to enter my password (only once). My plan is to use pexpect to spawn a bash session with sudo rights and to call scripts from there. Basically I always want to keep the session busy, whenever one script stopped, I want to start another. But while the scripts are running, I want the user to have control. Meaning: The scripts should be called after something like expect("root@"),