Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with parsing strings!
#1
Hello Python community!

I have problems with simple script which i created for gathering specific data from routers, so I would appreciate your help!

My script should do next:

1. SSH to router and type command "show system licence"
2. Output of that command is in few rows and columns, but I need to take specific part of string and print it out

I stucked at part 2, here is my code: 
import paramiko,string

JUNuser = 'xxx'
JUNpass = 'xxx'
JUNhost = 'xxx'

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(JUNhost, username=JUNuser, password=JUNpass)
stdin, stdout, stderr = ssh.exec_command("show system license")

output = stdout.readlines()
type(output)
final = output[3:4]
print '\n'.join(final) 
With this i managed to get specific row from original output.
Original output looks like:
Output:
License usage:                                   Licenses           Licenses           Licenses            Expiry   Feature name             used               installed           needed    scale-subscriber               0                 1000                  0                41 days
With part "final = output[3:4]" i managed to get:
Output:
scale-subscriber                      0         1000           0    41 days
What I want to achieve is to tell my script to get only this number of days when licence expire. So I want my script to show me only number 41!

Do you guys have idea how to do that? I am python beginner so be nice to me :)

Best Regards!
Reply


Messages In This Thread
Help with parsing strings! - by Cenzoooo - Jan-17-2017, 04:12 PM
RE: Help with parsing strings! - by snippsat - Jan-17-2017, 04:18 PM
RE: Help with parsing strings! - by Cenzoooo - Jan-18-2017, 07:11 AM
RE: Help with parsing strings! - by wavic - Jan-18-2017, 07:27 AM
RE: Help with parsing strings! - by Cenzoooo - Jan-18-2017, 07:54 AM
RE: Help with parsing strings! - by buran - Jan-18-2017, 08:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 816 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,816 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 2,544 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  Python file parsing, can't catch strings in new line Philia 5 4,004 Apr-29-2018, 01:09 PM
Last Post: snippsat
  lists, strings, and byte strings Skaperen 2 4,263 Mar-02-2018, 02:12 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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