cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1459
Views
5
Helpful
1
Replies

Python - My first script

Ciscomania
Level 1
Level 1

Hello Guys,

I created script which executes few outputs on Cisco Routers.

Script is working fine , it logs to device   and executes commands.

But I don't know how force Python to save those outputs to Text Document.
Please help.

import getpass
import sys
import telnetlib

print ("Script starts")

HOST = "71.61.14.36"

tn = telnetlib.Telnet(HOST, "33153",)
print ("Telnetting to device")

tn2 = telnetlib.Telnet(HOST, "33154",)
print ("Telnetting to device")


print ("Executing commands")
tn.write("\n\n\n\n")
tn.write("\n\n\n\n")
tn.write("enable\n")
tn.write("show ip interface brief\n")
tn.write("show interfaces description\n")


print ("Executing commands")
tn2.write("\n\n\n\n")
tn2.write("\n\n\n\n")
tn2.write("enable\n")
tn2.write("show ip interface brief\n")
tn2.write("show interfaces description\n")
tn2.close()
1 Reply 1

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

Without adding anything to your script why don't you just pipe the output to a text file:

 

# python myscript.py > some_text_file.txt

cheers,

Seb.