Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with print format
#6
There is something strange with your indent... get sure you are using soft-tabs with 4 spaces in your editor.

Anyway, I try to collect everything in a single code (I cannot test it as I have no access to your test machine)
import telnetlib
import re
HOST = "10.10.1.10"
user = "test"
password = "test@123"
telnet = telnetlib.Telnet(HOST)
#telnet.set_debuglevel(2)
telnet.read_until("Username: ",3)
telnet.write(user + "\n")
if password:
telnet.read_until("Password:",3)
telnet.write(password + "\n")
 
telnet.write("term len 0 \n")
telnet.read_until(">")
telnet.write("show ver \n")
telnet.write("Show ntp status \n")
telnet.write("Show ntp association\n")
telnet.write("show snmp \n")
telnet.read_until(">",10)
telnet.write("exit\n")
Veroutput = telnet.read_all()

Version = '<Missing>'
Image = '<Missing>'
ProcessorID = '<Missing>'
MACAddress = '<Missing>'
Model = '<Missing>'
SystemSerialNumber = '<Missing>'
NTPStatus = '<Missing>'
NTPsyncStatus = '<Missing>'
NTPAssociationDelay = '<Missing>'
SNMPlogging = '<Missing>'
SNMPAgentStatus = '<Missing>'

for line in Veroutput.split('\n'):
    if 'Version' in line:
        Version = line.split(',')[1]
    if 'image' in line:
        Raw_Image = line.split(':')[1][:-1]
        Image = Raw_Image[:-1]
    if 'Processor board ID' in line:
        ProcessorID = line.split(' ')[3]
    if 'MAC Address' in line:
        MACAddress = line.split(' ')[4]
    if 'Model number' in line:
        Model = line.split(':')[1]
    if 'System serial number' in line:
        SystemSerialNumber = line.split(':')[1]
    if 'Clock' in line:
        NTPStatus = line.split(',')[0]
        NTPsyncStatus = NTPStatus.split(' ')[2]
    if '*~' in line:
        NTPAssociationDelay = re.sub('\s{2,}', ' ', line).split(' ')[5]
    if 'logging:' in line:
        SNMPlogging = line.split(':')[1].strip()
    if 'agent' in line:
        SNMPAgentStatus = line.split(' ')[2]

# Now that all the lines are read, report the result
print('{} {} {} {} {} {} {} {} {} {} {}'.format(
    HOST, Version, Image, ProcessorID, MACAddress, Model, 
    SystemSerialNumber, NTPsyncStatus, NTPAssociationDelay,
    SNMPlogging, SNMPAgentStatus))
Notice that the print is outside of the for loop. Any missing data will appear as <Missing>.

Nevertheless your output is strange because it does not start with the HOST value and that one is for sure equal to 10.10.1.10 (is hardcoded in your script)
I suspect is not the output of your print command, maybe some trace in your script or a log written in the stdout by telnetlib.
Reply


Messages In This Thread
problem with print format - by anna - May-15-2018, 05:52 PM
RE: problem with print format - by nilamo - May-15-2018, 06:09 PM
RE: problem with print format - by anna - May-15-2018, 06:39 PM
RE: problem with print format - by killerrex - May-15-2018, 07:07 PM
RE: problem with print format - by anna - May-15-2018, 07:43 PM
RE: problem with print format - by killerrex - May-15-2018, 11:12 PM
RE: problem with print format - by anna - May-16-2018, 08:01 AM
RE: problem with print format - by anna - May-16-2018, 11:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with print command in super() akbarza 5 721 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  problem with spliting line in print akbarza 3 486 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  problem with print lists MarekGwozdz 4 792 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  Problem with print variable in print.cell (fpdf) muconi 0 703 Dec-25-2022, 02:24 PM
Last Post: muconi
  Print first day of the week as string in date format MyerzzD 2 2,091 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 3,056 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  C to Python code conversion print problem anakk1n 1 2,239 May-22-2020, 04:15 PM
Last Post: deanhystad
  Highscore problem, need to print top 5 Camiosobro123 5 5,037 Jan-29-2020, 03:31 PM
Last Post: ThiefOfTime
  Parquet format conversion problem Bilhardas 1 1,702 Nov-19-2019, 11:06 AM
Last Post: baquerik
  misunderstanding of format in print function Harvey 2 2,226 Oct-29-2019, 12:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020