Giter Club home page Giter Club logo

Comments (9)

matejv avatar matejv commented on August 16, 2024

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.

yaserelkhatib avatar yaserelkhatib commented on August 16, 2024

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.

yaserelkhatib avatar yaserelkhatib commented on August 16, 2024

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.

matejv avatar matejv commented on August 16, 2024

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.

yaserelkhatib avatar yaserelkhatib commented on August 16, 2024

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.

matejv avatar matejv commented on August 16, 2024

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.

yaserelkhatib avatar yaserelkhatib commented on August 16, 2024

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.

matejv avatar matejv commented on August 16, 2024

Thank you for your help and pointing me in the right direction.

Sure, no problem.

from exscript.

egroeper avatar egroeper commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.