telnetlib - define a variable getiing from a specif value from output

496 views Asked by At

I need to run a script to get a value from output, set a varible then use it inside of scrip. the script is this:

tn = telnetlib.Telnet(line)

        tn.read_until("Username: ")
        tn.write(user + "\n")
        tn.read_until("Password: ")
        tn.write(password + "\n")
        tn.write("enable \n")
        tn.write(password + "\n")
        ## GET VOIP INTERFACE
        tn.write("sh int desc | i VOIP \n")

the output will genarate something like this:

router01011#sh int desc | i VOIP Gi0/1.110 up up Local - VOIP

Then I need to get the first 10 characters (in this case would be Gi0/1.110) of the last line and put it in a variable string. How could I do that?

Thank you!

1

There are 1 answers

0
Jorge Alberto Rueda Flores On

With python, you could save the values in a variable and then

result = your_var[:10]

I hope this help you