admin管理员组文章数量:1296917
I am running the following script:
pxssh.PROMPT = "user@firewall>"
conn = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
conn.login(ip, user, pw, auto_prompt_reset=False, login_timeout=10)
conn.prompt(timeout=1)
conn.sendline("set cli pager off\r")
conn.prompt(timeout=1)
print(int(time.time()))
conn.sendline("debug dataplane pow performance all\r")
conn.prompt(timeout=1)
output = conn.before
conn.logout()
The script completes and returns the correct data, but it was taking 30s plus for each step until I added the timeout for the prompt. Now the login takes 33s, but the prompts take a second or so.
The login and each step are successful even with the delays.
I have used pexpect in the past and don't remember having this issue.
I was expecting that each command sent and each prompt would also send a "\r" or similar and cause the command to be entered on the cli and the response should be immediately returned.
An interactive session from the same host has each step completes immediately with no delay.
What have I missed? Or is this just expected behavior?
Edit:
Here is the sanitized output of the logging from the script as per the suggestion below. I'm not quite sure how to interpret the $ or why the output of the commands echo back with a prompt between each word...
^M([email protected]) Password: xxxxxxxxxxxxxxxxxxx
^M$
Last login: Mon Feb 17 11:24:19 2025 from 10.0.10.10^M^M$
^M$
^M$
^M$
Number of failed attempts since last successful login: 0^M$
^M$
^M$
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> set cli pager off^M$
set ^M^[[Klogan@Paloalto(passive)> set cli ^M^[[Klogan@Paloalto(passive)> set cli pager ^M^[[Klogan@Paloalto(passive)> set cli pager off^M$
logan@Paloalto(passive)> ^M$
logan@Paloalto(passive)> debug dataplane pow performance all^M$
debug ^M^[[Klogan@Paloalto(passive)> debug dataplane ^M^[[Klogan@Paloalto(passive)> debug dataplane pow ^M^[[Klogan@Paloalto(passive)> debug dataplane pow performance ^M^[[Klogan@Paloalto(passive)> debug dataplane pow performance all^M$
^M$
group max-us avg-us count total-us ac-max-us ac-avg-us ac-count ac-total-us^M$
flow_lookup 0 0.0 0 0 0 0.0 0 0^M$
flow_fastpath 0 0.0 0 0 1943467 45.8 11061157675 506606814217^M$
flow_slowpath 0 0.0 0 0 1951485 121.8 519672471 63332379045^M$
Edit 2:
Just clarification - I realize that some of the output prompts are mismatched "(active)>" vs "(passive)>". It does not change the behavior whether they match or not at this point. I have since updated the script appropriately. There is a method to determine the active device which I intend to implement shortly, however this will not solve this issue until I am able to fix the larger issue with the prompt.
I am running the following script:
pxssh.PROMPT = "user@firewall>"
conn = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
conn.login(ip, user, pw, auto_prompt_reset=False, login_timeout=10)
conn.prompt(timeout=1)
conn.sendline("set cli pager off\r")
conn.prompt(timeout=1)
print(int(time.time()))
conn.sendline("debug dataplane pow performance all\r")
conn.prompt(timeout=1)
output = conn.before
conn.logout()
The script completes and returns the correct data, but it was taking 30s plus for each step until I added the timeout for the prompt. Now the login takes 33s, but the prompts take a second or so.
The login and each step are successful even with the delays.
I have used pexpect in the past and don't remember having this issue.
I was expecting that each command sent and each prompt would also send a "\r" or similar and cause the command to be entered on the cli and the response should be immediately returned.
An interactive session from the same host has each step completes immediately with no delay.
What have I missed? Or is this just expected behavior?
Edit:
Here is the sanitized output of the logging from the script as per the suggestion below. I'm not quite sure how to interpret the $ or why the output of the commands echo back with a prompt between each word...
^M([email protected]) Password: xxxxxxxxxxxxxxxxxxx
^M$
Last login: Mon Feb 17 11:24:19 2025 from 10.0.10.10^M^M$
^M$
^M$
^M$
Number of failed attempts since last successful login: 0^M$
^M$
^M$
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> $
^M$
logan@Paloalto(passive)> set cli pager off^M$
set ^M^[[Klogan@Paloalto(passive)> set cli ^M^[[Klogan@Paloalto(passive)> set cli pager ^M^[[Klogan@Paloalto(passive)> set cli pager off^M$
logan@Paloalto(passive)> ^M$
logan@Paloalto(passive)> debug dataplane pow performance all^M$
debug ^M^[[Klogan@Paloalto(passive)> debug dataplane ^M^[[Klogan@Paloalto(passive)> debug dataplane pow ^M^[[Klogan@Paloalto(passive)> debug dataplane pow performance ^M^[[Klogan@Paloalto(passive)> debug dataplane pow performance all^M$
^M$
group max-us avg-us count total-us ac-max-us ac-avg-us ac-count ac-total-us^M$
flow_lookup 0 0.0 0 0 0 0.0 0 0^M$
flow_fastpath 0 0.0 0 0 1943467 45.8 11061157675 506606814217^M$
flow_slowpath 0 0.0 0 0 1951485 121.8 519672471 63332379045^M$
Edit 2:
Just clarification - I realize that some of the output prompts are mismatched "(active)>" vs "(passive)>". It does not change the behavior whether they match or not at this point. I have since updated the script appropriately. There is a method to determine the active device which I intend to implement shortly, however this will not solve this issue until I am able to fix the larger issue with the prompt.
Share Improve this question edited Feb 17 at 21:39 meuh 12.3k2 gold badges33 silver badges47 bronze badges asked Feb 11 at 18:16 LoganLogan 93 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 0You are not setting the correct PROMPT
attribute. It should be on the
pxssh instance. Start the code with
conn = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
conn.PROMPT = "user@firewall>"
本文标签: pythonSlow Execution of Pexpect Scriptseems to be hitting 30s timeout each stepStack Overflow
版权声明:本文标题:python - Slow Execution of Pexpect Script - seems to be hitting 30s timeout each step - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741642306a2389988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
\r
in yoursendline
calls since an end-of-line character is implied bysendline
. Probably not the issue, but could be. – kindall Commented Feb 11 at 19:19$
comes fromcat -e
and shows explicitly the end of the line. This ensures you see any space characters that might be there. Hence^M$
means we got the usual end-of-line 2 chars\r\n
, carriage-return line-feed. The repeated partial completion of the commands seems to be an attempt by the firewall to allow you to entertab
or a similar char to get a list of possible words that fit there, an inline help. (The^M^[[K
has^[
, ie escape, so tells the terminal emulator to goto end of line.) You might have a command, likeset batch
orset noninteractive
to stop it doing this. – meuh Commented Feb 17 at 22:11