Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-26-2016, 04:13 PM
andymc andymc is offline
Registered User
 
Join Date: Sep 2015
Posts: 14
python - ignore strings

Firstly, i am now using python scripting everyday in my job, this is making my life so much easier, so thanks for all your hard work.

My First Question :: I log into Cisco Devices, thousands of them, i then send my command, this could be any command, doesn't matter what i sending.

I then use ReadString with the Char '#'

%99 of the time, this is perfect, but on the odd occasion an engineer has included the Char '#' in their description. This causes my code to stop reading and move onto the next device.

So i wonder, is there a way to ignore/escape any possibly early # ?

My Second question :: Is there a way to just read the whole screen, i don't want to read until a certain char, i want the whole screen ?

Andy
Reply With Quote
  #2  
Old 05-26-2016, 04:57 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 952
Yes, you can read the whole screen if you want... the problem is determining when it's "safe" to do so (when has all the data arrived that you want to read? What if there's more data that you want that doesn't fit on just the screen?)

Typically the solution to your general problem is to be more specific/unique about what it is you want SecureCRT to stop reading at. If all you specify is a "#" char, that's going to get you into the exact trouble you're in.

However, if you specify the entire shell prompt, that's unique enough to be more consistent at capturing all the data you need.

There are a number of examples that show how to go about detecting the shell prompt, but here's one that might not only give you info about solving your immediate problem, but also show you some other tricks as well.
Cisco Save Running/Startup Config to Local File

If you're really bent on reading in the entire screen, you simply need to use the Screen.Get() or Screen.Get2() APIs. Both of these are documented in SecureCRT's built-in help. See the Scripting -> Script Objects Reference -> Screen Object topic, and click on the Get or Get2 links there to see what params you'll need.

Don't be afraid to use the Screen.Rows and Screen.Columns properties to tell you how big your screen is right now, so you don't have to use magic numbers.

You can always use the magic number of 1 for starting row and/or starting col if you're looking to get the entire screen. Get2() will return CRLF-separated lines, so it's probably the better choice -- again, if you're unable to specify anything more complete with your ReadString() technique. There's a VBScript example that shows Get2() in action... it's in VBScript, but the line of code showing the Get2() isn't very much far removed from Python syntax, so it's sufficient as an idea-starter.

If you haven't spotted it yet, the Script Examples "sticky" is a good place to go for other examples to whet your automation appetite.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:57 AM.