Script cuts off output too soon

This is the place for queries that don't fit in any of the other categories.

Script cuts off output too soon

Postby ippy98 » Wed Dec 18, 2013 3:40 pm

I wasn't sure if this should go in the networking board or not, since I am trying to log into routers, however I don't think my script issues have anything to do with the routers themselves....
I am trying to write a script that will log into various routers we have on the network and determine what type it is. My script can successfully log into a router and start running commands.

What I don't know is why it stops early in the middle of what it is capturing.

I get logged into the router, then run a "show version" command, which then is waiting for output. What the python script receives/sees is:

Cisco Internetwork Operating System Software
IOS (tm) s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2(18)SXF7, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2006 by cisco Systems, Inc.
Compiled Thu 23-Nov-06 06:00 by kellythw
Image text-base: 0x40101040, data-base: 0x42D98000

ROM: System Bootstrap, Version 12.2(17r)SX5, RELEASE SOFTWARE (fc1)
BOOTLDR: s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2(18)SXF7, RELEASE SOFTWARE (fc1)

milnew6509-1 uptime is 6 years, 25 weeks, 9 hours, 25 minutes
Time since milnew6509-1 switched to active is 6 years, 25 weeks, 8 hours, 51 minutes
System returned to ROM by power cycle (SP by power on)
System restarted at 01:31:54 CDT Thu Jun 28 2007
System image file is "disk0:s72033-advipservicesk9_wan-mz.122-18.sxf7"


This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of C


It cuts off here in the middle of the text and the script stops (no error messages or exceptions), and never gets to the portion that contains what is "expecting"


Here is an example of what it is SUPPOSED to capture, you can see it's a lot more info:

Cisco Internetwork Operating System Software
IOS (tm) s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2(18)SXF7, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2006 by cisco Systems, Inc.
Compiled Thu 23-Nov-06 06:00 by kellythw
Image text-base: 0x40101040, data-base: 0x42D98000

ROM: System Bootstrap, Version 12.2(17r)SX5, RELEASE SOFTWARE (fc1)
BOOTLDR: s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2(18)SXF7, RELEASE SOFTWARE (fc1)

<router> uptime is 6 years, 25 weeks, 9 hours, 28 minutes
Time since <router> switched to active is 6 years, 25 weeks, 8 hours, 54 minutes
System returned to ROM by power cycle (SP by power on)
System restarted at 01:31:54 CDT Thu Jun 28 2007
System image file is "disk0:s72033-advipservicesk9_wan-mz.122-18.sxf7"


This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

cisco WS-C6509 (R7000) processor (revision 2.0) with 983008K/65536K bytes of memory.
Processor board ID SCA050800ZL
SR71000 CPU at 600Mhz, Implementation 0x504, Rev 1.2, 512KB L2 Cache
Last reset from s/w reset
SuperLAT software (copyright 1990 by Meridian Technology Corp).
X.25 software, Version 3.0.0.
Bridging software.
TN3270 Emulation software.
27 Virtual Ethernet/IEEE 802.3 interfaces
252 Gigabit Ethernet/IEEE 802.3 interfaces
1917K bytes of non-volatile configuration memory.
8192K bytes of packet buffer memory.

65536K bytes of Flash internal SIMM (Sector size 512K).
Configuration register is 0x2102




So here is a snippet of my code, we are using python 2.4.3 with pexpect module
Code: Select all
fout = file("pylog.log", 'w')

li = pexpect.spawn ('ssh ' + user + '@' + router)
li.logfile = fout
pw = li.expect (['yes/no', 'assword:'])
if pw==0:
        li.sendline ('yes')
if pw==1:
        li.sendline (psswd)
li.expect (router + '#')
li.sendline ("term len 0")
li.expect (router + '#')
li.sendline ("show ver") 
#li.expect (pexpect.EOF)
print li.before   

time.sleep(1.0)   
type = li.expect (['WS-C6509', 'Operating', 'IOS', pexpect.TIMEOUT, pexpect.EOF])
if type==0:
        print ("Model is 6500")
#if type==1:
#       print ("Match 1st line")
if type==2:
        print ("2nd line")
if type==3:
        print 'No match, timed out'
Last edited by Yoriz on Wed Dec 18, 2013 4:56 pm, edited 1 time in total.
Reason: first post lock
ippy98
 
Posts: 1
Joined: Wed Dec 18, 2013 3:27 pm

Re: Script cuts off output too soon

Postby micseydel » Fri Dec 20, 2013 2:50 am

This doesn't look like a networking question, since you're outsourcing all the network part to ssh. I'm not exactly sure what's going on here though, is the part you have in quotes from print li.before? Have you used a debugger such as pdb to detect what line your program reaches? I'm not sure if you're saying that the script silently aborts or if you're just not getting the proper output on a specific line.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1295
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: 7stud, Bing [Bot] and 3 guests