07-23-2019 09:05 AM
Hello,
I'm using the guest shell in on a 9300 and trying to save a run config txt file and then print out the run config txt file in the python interpreter. But it's not working, see below:
>>> cli_output = cli("sh run")
>>> type(cli_output)
<type 'str'>
>>> f = open("run_config.txt" , "w+")
>>> f.write("cli_output")
>>> print f
<open file 'run_config.txt', mode 'r' at 0x22b4d20>
I'm expecting to see the run config file print out on the interpreter but it's not happening.
Also how can I scp this file over to my desktop? Do I need to copy it over the switch directory? Not sure how that's done.
Thanks
07-23-2019 10:56 AM
>>> print f
for line in f:
print (line)
07-23-2019 11:43 AM
Thanks for the reply, so I tried the for loop and getting the below:
>>> f = open("run_config1.txt" , "w+")
>>> f.write("run_config")
>>> for lines in f:
... print (lines)
...
>>>
>>>
>>> f = open("run_config1.txt" , "w+")
>>> f.write("run_config")
>>> f1 = f.readlines()
>>> for lines in f1:
... print lines
...
>>>
Don't think I'm getting the right result?
Thanks
07-23-2019 12:57 PM
Maybe close file and open again
f = open("run_config1.txt" , "w+")
f.write("run_config")
f.close()
f = open("run_config1.txt" , "r")
for line in f:
print (line)
07-23-2019 12:55 PM
I see the issue when I just try reading the file, it only outputting "cli_output" , it's not storing the value of the variable in the file:
>>> f = open("run_config.txt" , "r")
>>> contents = f.read()
>>> print contents
cli_output
how can I pass the contents of the variable to my txt file?
Thanks
08-01-2019 07:58 AM
So i'm not sure if this is it, but in you're first post, you're doing
f.write("cli_output")
did you mean
f.write(cli_output)
???
could have something to do with it. after this test, would you mind pasting the results of a
dir() and vars()
on both cli_output and f after the write?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide