View Single Post
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?
# $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 =,term_info).group(1)
term_width =,term_info).group(2)

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

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

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

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

        #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