Comments (9)
After every command sent exscript searches the reposnse from router for a prompt. By default the regex for the prompt is something like /^\w#/ which will obviusly fail when the router is waiting for you to enter each line of your banner.
Before you start configuring the banner you should set the prompt to empty (/.*/) and reset it before you send the last line of the banner. This template works for me on a Cisco router:
conf t
{connection.set_prompt(/(Enter TEXT|.*)/)}
banner motd |
test1
multiple lines
good
{connection.set_prompt()}
|
end
from exscript.
Thank you for the explanation. This makes sense.
Yaser Elkhatib
Network Engineer
IMC Financial Markets
W# (312) 244-3339
C# (708) 790-5644
On Friday, September 5, 2014 3:05 AM, Matej Vadnjal [email protected] wrote:
After every command sent exscript searches the reposnse from router for a prompt. By default the regex for the prompt is something like /^\w#/ which will obviusly fail when the router is waiting for you to enter each line of your banner.
Before you start configuring the banner you should set the prompt to empty (/./) and reset it before you send the last line of the banner. This template works for me on a Cisco router:
conf t
{connection.set_prompt(/(Enter TEXT|.)/)}
banner motd | test1 multiple lines good
{connection.set_prompt()}
|
end
—
Reply to this email directly or view it on GitHub.
from exscript.
BTW, I couldn't get your code to work on Arista switches. Here is the prompt:
xxx01(config)#banner motd
Enter TEXT message. Type 'EOF' on its own line to end.
So I tried this and other veriations of regex without luck:
conf t
{connection.set_prompt(/(Enter\ TEXT\ message.\ Type\ 'EOF'\ on\ its\ own\ line\ to\ end.)/)}
banner motd |
test1
multiple lines
good
EOF
{connection.set_prompt()}
|
end
What do you think the problem is?
sxxxx01 error: Device said:
{connection.set_prompt(/(Enter\ TEXT\ message.\ Type\ 'EOF'\ on\ its\ own\ line\ to\ end.)/)}
% Invalid input
sxxxx01(config)#
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/workqueue/Job.py", line 64, in run
self.function(self)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/Queue.py", line 80, in _wrapped
result = func(job, host, conn, _args, *_kwargs)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/util/decorator.py", line 110, in decorated
return function(job, host, conn, _args, *_kwargs)
File "/usr/local/bin/massdeploy.py", line 88, in execute_commands
conn.execute(sendcommand)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/protocols/Protocol.py", line 888, in execute
return self.expect_prompt()
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/protocols/Protocol.py", line 998, in expect_prompt
raise InvalidCommandException('Device said:\n' + self.response)
InvalidCommandException: Device said:
{connection.set_prompt(/(Enter\ TEXT\ message.\ Type\ 'EOF'\ on\ its\ own\ line\ to\ end.)/)}
% Invalid input
sxxxx01(config)#
sxxxx01 finally failed.
sxxxx01: Device said:
{connection.set_prompt(/(Enter\ TEXT\ message.\ Type\ 'EOF'\ on\ its\ own\ line\ to\ end.)/)}
% Invalid input
sxxxx01(config)#
Thank you for your time.
Yaser Elkhatib
Network Engineer
IMC Financial Markets
W# (312) 244-3339
C# (708) 790-5644
On Friday, September 5, 2014 3:05 AM, Matej Vadnjal [email protected] wrote:
After every command sent exscript searches the reposnse from router for a prompt. By default the regex for the prompt is something like /^\w#/ which will obviusly fail when the router is waiting for you to enter each line of your banner.
Before you start configuring the banner you should set the prompt to empty (/./) and reset it before you send the last line of the banner. This template works for me on a Cisco router:
conf t
{connection.set_prompt(/(Enter TEXT|.)/)}
banner motd | test1 multiple lines good
{connection.set_prompt()}
|
end
—
Reply to this email directly or view it on GitHub.
from exscript.
I'm not familiar with Arista switches, so I'm not sure this will be correct.
Why are you sending a pipe (|) at the end of banner motd command? From your example this is not needed on Arista. That's a special character that tells a Cisco switch that you are finished with your banner. I bet this is the line that causes your Invalid input error.
Also your prompt regex will only allow you to configure the first line of the banner since you are matching only the string "Enter TEXT message. Type 'EOF' on its own line to end.". All the subsequent lines will have nothing you could match as a prompt so you might as well match anything (.*).
Try this:
conf t
{connection.set_prompt(/(.*)/)}
banner motd
test1
multiple lines
good
{connection.set_prompt()}
EOF
end
from exscript.
That didn't work either:
xxxx01 error: Device said:
{connection.set_prompt(/(._)/)}
% Invalid input
xxxx01(config)#
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/workqueue/Job.py", line 64, in run
self.function(self)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/Queue.py", line 80, in _wrapped
result = func(job, host, conn, *args, *_kwargs)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/util/decorator.py", line 110, in decorated
return function(job, host, conn, _args, _kwargs)
File "/usr/local/bin/massdeploy.py", line 88, in execute_commands
conn.execute(sendcommand)
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/protocols/Protocol.py", line 888, in execute
return self.expect_prompt()
File "/usr/lib/python2.6/site-packages/Exscript-DEVELOPMENT-py2.6.egg/Exscript/protocols/Protocol.py", line 998, in expect_prompt
raise InvalidCommandException('Device said:\n' + self.response)
InvalidCommandException: Device said:
{connection.set_prompt(/(.)/)}
% Invalid input
xxxx01(config)#
I have a definition in my massdeploy script that basically tells it to to take the command list, which is what you gave me in the previous email, and paste it line by line on the device like this:
def execute_commands(job, host, conn):
for sendcommand in commandlist:
conn.execute(sendcommand)
Could that be the problem for that fact that python is not reading this line but instead is trying to execute it on the switch?{connection.set_prompt(/(.*)/)}
I also tried to make it conn instead of connection and still had the same error above. I'll continue working and trying this today and I appreciate your help.
Yaser Elkhatib
Network Engineer
IMC Financial Markets
W# (312) 244-3339
C# (708) 790-5644
On Wednesday, September 24, 2014 1:09 AM, Matej Vadnjal [email protected] wrote:
I'm not familiar with Arista switches, so I'm not sure this will be correct.
Why are you sending a pipe (|) at the end of banner motd command? From your example this is not needed on Arista. That's a special character that tells a Cisco switch that you are finished with your banner. I bet this is the line that causes your Invalid input error.
Also your prompt regex will only allow you to configure the first line of the banner since you are matching only the string "Enter TEXT message. Type 'EOF' on its own line to end.". All the subsequent lines will have nothing you could match as a prompt so you might as well match anything (.).
Try this:
conf t
{connection.set_prompt(/(.)/)}
banner motd
test1
multiple lines
good
{connection.set_prompt()}
EOF
end
—
Reply to this email directly or view it on GitHub.
from exscript.
Could that be the problem for that fact that python is not reading this line but instead is trying to execute it on the switch?{connection.set_prompt(/(.*)/)}
Well, yeah. The example I gave you was for a template (https://github.com/knipknap/exscript/wiki/Template-Examples) that you use with the exscript command. But you are using the Python API.
So instead of passing the string "{connection.set_prompt(/(.*)/)}" to conn.execute() method you want to call conn.set_prompt() with the right regex.
from exscript.
Metaj,
Here is how I fixed it:
Send commands to individual switches
def execute_commands(job, host, conn):
if "banner motd" in commandlist:
conn.set_prompt(r'.+')
for sendcommand in commandlist:
if "EOF" in sendcommand:
conn.set_prompt()
conn.execute(sendcommand)
else:
for sendcommand in commandlist:
conn.execute(sendcommand)
Thank you for your help and pointing me in the right direction.
Yaser Elkhatib
Network Engineer
IMC Financial Markets
W# (312) 244-3339
C# (708) 790-5644
On Wednesday, September 24, 2014 8:11 AM, Matej Vadnjal [email protected] wrote:
Could that be the problem for that fact that python is not reading this line but instead is trying to execute it on the switch?{connection.set_prompt(/(.)/)}
Well, yeah. The example I gave you was for a template (https://github.com/knipknap/exscript/wiki/Template-Examples) that you use with the exscript command. But you are using the Python API.
So instead of passing the string "{connection.set_prompt(/(.)/)}" to conn.execute() method you want to call conn.set_prompt() with the right regex.
—
Reply to this email directly or view it on GitHub.
from exscript.
Thank you for your help and pointing me in the right direction.
Sure, no problem.
from exscript.
Seems like the problem is solved.
BTW: I think the mailinglist would be a better place for asking such questions:
http://groups.google.com/group/exscript/
from exscript.
Related Issues (20)
- Authentication with _paramiko_auth_password failed: Authentication timeout
- Support PrivateKey.from_private_key_file(obj)
- Problem in connecting nodes of Cisco Terminal Server HOT 1
- Exscript needs to negotiate ciphers automatically with older SSH systems... HOT 2
- Generic method to run a remote sudo command
- Exscript ssh2.interact() seems to be broken under linux HOT 1
- prompt with questions
- breaks with python3.10 due to deprecated (and now removed) use of collections.Callable
- API docs missing at readthedocs
- Expect and waitfor error with ValueError HOT 4
- Telnet does not seem to work HOT 1
- iox_xr driver modification needed
- Fundamental incompatibility of Threading and Multiprocessing (Python) HOT 2
- ModuleNotFoundError: No module named 'imp' HOT 2
- Upgrade build system to PEP 517
- How to connect to the emulator terminal of Android Studio for Android Emulator
- infinit loop when execute use parameter read_until_match
- request for github tags or pypi source distributions with new releases HOT 1
- telnetlib several times slower than the one from stdlib HOT 2
- Exscript.protocols.exception.TimeoutException: Error while waiting for response from device HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exscript.