Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-28-2020, 02:47 PM
garrettwilliams garrettwilliams is offline
Registered User
 
Join Date: Dec 2020
Posts: 13
screen.readstring/get --> Unable to position start?

Hey all,

I feel like I must be missing something simple. I'm trying to put together a simple script to pull the running config off a device and drop it into a text file line by line.
I know there are examples of doing exactly that, but I'd like something as watered down as possible so I can easily troubleshoot / make additions.

What I'm doing here is checking 'show term', setting term length to 0, and then doing my show runn. This script is going up and grabbing the output of the 'show term'. I cannot, no matter what I've tried, just get the thing to read after show runn. What am I missing here?
Code:
# $language = "python3"
# $interface = "1.0"


import os
import re



#send show term command, and snag the terminal length and width.



crt.Screen.Send("sh term\n")
crt.Screen.WaitForString("Session Timeout")
screenrow = crt.Screen.CurrentRow - 1
term_info = crt.Screen.Get(screenrow, 1, screenrow, 30).strip(" ")
re_string = r'Length: (\d+) lines, Width: (\d+)'
term_length = re.search(re_string,term_info).group(1)
term_width = re.search(re_string,term_info).group(2)




crt.Screen.Synchronous = True
filename = 'C:\Tools\output.txt'
fp = open(filename, "w+")

crt.Screen.Send("term length 0\n")
crt.Screen.WaitForString("\n")

prompt = "Nexus9000v#"
wait_strs = ['\n', prompt]
with open(filename, "w+") as fp:
    crt.Screen.Send("sh runn\n")
    crt.Screen.WaitForString('\n')
    while True:

        nextline = crt.Screen.ReadString(wait_strs, 30)
        if crt.Screen.MatchIndex == 1:
            nextline = nextline.strip(" ")
            crt.Dialog.MessageBox(nextline)
            fp.write(nextline + "\n")
        elif crt.Screen.MatchIndex == 2:
            break


        #result = crt.Screen.WaitForStrings(wait_strs)
        #if result == 2:
        #    break
        #screenrow = crt.Screen.CurrentRow - 1
        #line_info = crt.Screen.Get(screenrow, 1, screenrow, 30).strip(" ")
        #fp.write(line_info + '\n')

Last edited by cboyack; 12-29-2020 at 07:03 AM. Reason: Please use the [CODE] and [/CODE] tags to denote a script
Reply With Quote
 


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 12:40 AM.