Someone know pexpect module?
I've a problem working with it...
I need to run some commands on remote hosts, like ls, df -k etc..All right.
Although, when i launch a command that have a "more" inside, i don't know
what i must expect!
An example:
if i want to run an "ls -l | more" on a remote host, it don't return me a
prompt, but a "-------------More-------------"...thus i don't know how much
this.
I've tried with:
child.expect('.*')
it works, but do not return any value.
Any idea?
I hope to have clearly explained my problem with my bad english...:-)
Thank you in advance
Regards
Gianluca Trombetta 8 3278
On Fri, 14 May 2004 19:50:54 +0200, Gianluca Trombetta wrote: Someone know pexpect module? I've a problem working with it...
I need to run some commands on remote hosts, like ls, df -k etc..All right. Although, when i launch a command that have a "more" inside, i don't know what i must expect!
Why don't you use a local more ? Or write your own "more" in python.
Simon.
On 2004-05-14, Gianluca Trombetta <gi****************@tin.it> wrote: Someone know pexpect module? I've a problem working with it...
I need to run some commands on remote hosts, like ls, df -k etc..All right. Although, when i launch a command that have a "more" inside, i don't know what i must expect! An example:
if i want to run an "ls -l | more" on a remote host, it don't return me a prompt, but a "-------------More-------------"...thus i don't know how much this.
The only reason I can see for piping the command through more would
be if there were a person sitting there wanting to read the output
before going on to read the next page of output. That seems counter
to the idea of using pexpect to automate the process. Do you
really need to pipe through more?
hmmm, i'm not so stupid...:-).
The command ls -l | more was an example...i'm not really need to run ls -l |
more in an automate program.
But I need to run some cisco commands like "show ip bgp summary", this
command print a table and put a "More" by default, if the table is too big
for a single terminal screen.
So I need to remove this behavior because if I match the " --More-- " with
expect module i can match only the first one "More", then this the program
crash and receives a timeout.
Hi
Gianluca
"Lee Harr" <mi*****@frontiernet.net> ha scritto nel messaggio
news:P9*****************@news01.roc.ny... On 2004-05-14, Gianluca Trombetta <gi****************@tin.it> wrote: Someone know pexpect module? I've a problem working with it...
I need to run some commands on remote hosts, like ls, df -k etc..All
right. Although, when i launch a command that have a "more" inside, i don't
know what i must expect! An example:
if i want to run an "ls -l | more" on a remote host, it don't return me
a prompt, but a "-------------More-------------"...thus i don't know how
much this.
The only reason I can see for piping the command through more would be if there were a person sitting there wanting to read the output before going on to read the next page of output. That seems counter to the idea of using pexpect to automate the process. Do you really need to pipe through more?
-- http://mail.python.org/mailman/listinfo/python-list
In article <ma************************************@python.org >,
Gianluca Trombetta <gi****************@tin.it> wrote: hmmm, i'm not so stupid...:-). The command ls -l | more was an example...i'm not really need to run ls -l | more in an automate program. But I need to run some cisco commands like "show ip bgp summary", this command print a table and put a "More" by default, if the table is too big for a single terminal screen. So I need to remove this behavior because if I match the " --More-- " with expect module i can match only the first one "More", then this the program crash and receives a timeout.
* Gianluca Trombetta <gi****************@tin.it> [2004-05-17 09:10]: But I need to run some cisco commands like "show ip bgp summary", this command print a table and put a "More" by default, if the table is too big for a single terminal screen. So I need to remove this behavior because if I match the " --More-- " with expect module i can match only the first one "More", then this the program crash and receives a timeout.
Why don't you post your code and the traceback you're getting. I think
you should be able to expect the "More" multiple times.
Try using expect with a list argument, and detect which one matched.
[untested]
console = pexpect.spawn("whatever_command_you_use")
# probably other stuff here (enabling, etc.) ...
console.sendline("sh ip bgp summ")
# look for more or prompt
return_index = console.expect([" --More-- ","#"])
while return_index == 0:
console.send(" ")
return_index = console.expect([" --More-- ","#"])
# matched prompt, so now you're good to go.
Note, that you may have to save the console.before in the while loop, so
you don't lose it before you match the prompt.
HTH-
John
P.S. [OT]: The cisco command I use to disable the pager is:
# terminal length 0
First of all, look up the manual for Cisco's 'show' command. See if there
is a way to turn off the paging. If not, try to fool cisco into thinking
you have a very large page size on your terminal (e.g. 10,000 lines).
If this is not possible, you can loop in your python script -:
while 1:
i=child.expect('--More--',pexpect.TIMEOUT)
if i==0:
child.sendline(' ')
else:
break
Adrian.
Gianluca Trombetta wrote: hmmm, i'm not so stupid...:-). The command ls -l | more was an example...i'm not really need to run ls -l | more in an automate program. But I need to run some cisco commands like "show ip bgp summary", this command print a table and put a "More" by default, if the table is too big for a single terminal screen. So I need to remove this behavior because if I match the " --More-- " with expect module i can match only the first one "More", then this the program crash and receives a timeout.
Hi Gianluca "Lee Harr" <mi*****@frontiernet.net> ha scritto nel messaggio news:P9*****************@news01.roc.ny... On 2004-05-14, Gianluca Trombetta <gi****************@tin.it> wrote: > Someone know pexpect module? > I've a problem working with it... > > I need to run some commands on remote hosts, like ls, df -k etc..All right. > Although, when i launch a command that have a "more" inside, i don't know > what i must expect! > An example: > > if i want to run an "ls -l | more" on a remote host, it don't return me a > prompt, but a "-------------More-------------"...thus i don't know how much > this. >
The only reason I can see for piping the command through more would be if there were a person sitting there wanting to read the output before going on to read the next page of output. That seems counter to the idea of using pexpect to automate the process. Do you really need to pipe through more?
-- http://mail.python.org/mailman/listinfo/python-list
Ooops - forgot the search for the prompt :-(
Change the expect line to -:
i=child.expect(['--More--', PROMPT],pexpect.TIMEOUT)
(Assumes PROMPT evaluates to a regular expression matching the cisco
prompt).
Adrian Casey wrote: First of all, look up the manual for Cisco's 'show' command. See if there is a way to turn off the paging. If not, try to fool cisco into thinking you have a very large page size on your terminal (e.g. 10,000 lines).
If this is not possible, you can loop in your python script -:
while 1: i=child.expect('--More--',pexpect.TIMEOUT) if i==0: child.sendline(' ') else: break
Adrian.
Gianluca Trombetta wrote:
hmmm, i'm not so stupid...:-). The command ls -l | more was an example...i'm not really need to run ls -l | more in an automate program. But I need to run some cisco commands like "show ip bgp summary", this command print a table and put a "More" by default, if the table is too big for a single terminal screen. So I need to remove this behavior because if I match the " --More-- " with expect module i can match only the first one "More", then this the program crash and receives a timeout.
Hi Gianluca "Lee Harr" <mi*****@frontiernet.net> ha scritto nel messaggio news:P9*****************@news01.roc.ny... On 2004-05-14, Gianluca Trombetta <gi****************@tin.it> wrote: > Someone know pexpect module? > I've a problem working with it... > > I need to run some commands on remote hosts, like ls, df -k etc..All right. > Although, when i launch a command that have a "more" inside, i don't know > what i must expect! > An example: > > if i want to run an "ls -l | more" on a remote host, it don't return > me a > prompt, but a "-------------More-------------"...thus i don't know how much > this. >
The only reason I can see for piping the command through more would be if there were a person sitting there wanting to read the output before going on to read the next page of output. That seems counter to the idea of using pexpect to automate the process. Do you really need to pipe through more?
-- http://mail.python.org/mailman/listinfo/python-list
Great!
I've disable the pager with the command "terminal length 0" and now it seem
work very well.
Thank you very much John and thank to all other!
Regards,
Gianluca Trombetta
"John Hazen" <jo**@hazen.net> ha scritto nel messaggio
news:20********************@gate2.hazen.net... * Gianluca Trombetta <gi****************@tin.it> [2004-05-17 09:10]: But I need to run some cisco commands like "show ip bgp summary", this command print a table and put a "More" by default, if the table is too
big for a single terminal screen. So I need to remove this behavior because if I match the " --More-- "
with expect module i can match only the first one "More", then this the
program crash and receives a timeout.
Why don't you post your code and the traceback you're getting. I think you should be able to expect the "More" multiple times.
Try using expect with a list argument, and detect which one matched.
[untested]
console = pexpect.spawn("whatever_command_you_use") # probably other stuff here (enabling, etc.) ... console.sendline("sh ip bgp summ") # look for more or prompt return_index = console.expect([" --More-- ","#"]) while return_index == 0: console.send(" ") return_index = console.expect([" --More-- ","#"]) # matched prompt, so now you're good to go.
Note, that you may have to save the console.before in the while loop, so you don't lose it before you match the prompt.
HTH-
John
P.S. [OT]: The cisco command I use to disable the pager is: # terminal length 0
-- http://mail.python.org/mailman/listinfo/python-list This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Adrian Casey |
last post by:
I have a collection of tcl expect scripts which I am converting to python
using the excellent pexpect module (http://pexpect.sourceforge.net/). So
far I've had great success in getting all my...
|
by: Baillargeon, Sonny |
last post by:
I am trying to use a pexpect script using python v2.3.4 with pexpect
module .999 on Solaris 8.
I try to execute this script.
#!/usr/bin/env python
'''This runs "ls -l" on a remote host using...
|
by: Eric Myers |
last post by:
Hello folks:
(This message is also posted on the help forum at the pexpect
sourceforge page, but all indentation in the code got stripped away
when I submitted the post.)
For some time I've...
|
by: yellowblueyellow |
last post by:
Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the
username is 'admin' and password is 'abc123' so far i have the
following code
import pexpect
import sys
import time...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |