Python Forum
Save outputs to Desktop - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: General Coding Help (
+--- Thread: Save outputs to Desktop (/Thread-Save-outputs-to-Desktop)

Save outputs to Desktop - cisicomania - Aug-31-2018


I wrote my first script.
It is logging to 2 Router's console\CLI and executing few commands.
Afterwards in Router's console I have outputs which shows me for example IP Addresing
R1#sho ip int bri Interface IP-Address OK? Method Status Protocol Ethernet0/0 unassigned YES unset administratively down down Ethernet0/1 unassigned YES unset administratively down down Ethernet0/2 unassigned YES unset administratively down down Ethernet0/3 unassigned YES unset administratively down down Loopback0 YES manual up up Loopback1 YES manual up up R1#show interface description Interface Status Protocol Description Et0/0 admin down down Et0/1 admin down down Et0/2 admin down down Et0/3 admin down down Lo0 up up Lo1 up up R1#
My question is how to save those outputs to my Desktop in text document format.

import getpass
import sys
import telnetlib

print ("Script starts")

HOST = ""

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

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

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

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

RE: Save outputs to Desktop - Gribouillis - Aug-31-2018

I don't have the answer, but there is an impressive wrapper of telnetlib with logging capabilities in the robotframework source code, you could perhaps find ideas here.