Sponsored Content
Full Discussion: Python script cuts off early
Top Forums Shell Programming and Scripting Python script cuts off early Post 302880248 by ippy98 on Wednesday 18th of December 2013 10:46:52 AM
Old 12-18-2013
Display Python script cuts off early

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:

Quote:
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:

Quote:
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:
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'

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

multiple cuts syntax problem

Hi All, I need some help with multiple cut and paste, at the moment I have a shell script that uses the following cuts ( this is just some) cut -c1-92 WAITING > col1 .....etc etc etc cut -c93-98 WAITING > col17 # blank_spaces cut -c99-104 WAITING > col18 # Date cut -c105... (12 Replies)
Discussion started by: Gerry405
12 Replies

2. UNIX for Advanced & Expert Users

Unknown event - daemon mode cuts programs from resources

Hi Guys. First of all Im not keen on os stuff, thus not sure what I should look for to solve my problem, Thats why Im posting before getting deeper into forums. Here is my problem. Im working on academic network - Solaris 7-10. Where parts of configuration is made by students (Im still one).... (1 Reply)
Discussion started by: baranowb
1 Replies

3. Solaris

Custom short cuts not working on JDS

Hello, I had created a shortcut to open up a gnome-terminal by pressing <Alt>m. This worked fine, until I logged out and logged back in. gnome-terminal no longer opens. However, the process is created, as evidenced by the gnome-terminal showing up on my process list. I've created and deleted... (1 Reply)
Discussion started by: cooldude
1 Replies

4. Shell Programming and Scripting

Multiple echos and cuts too slow

Hi guys, hopefully this hasn't been asked before - couldn't see the question anywhere. I have a large number of timestamps (hh-mm-ss-millisecond) that I need to find the difference between e.g.: 14-11-07-513 14-11-07-644 Now the script that I have just knocked up is horrifically slow,... (4 Replies)
Discussion started by: dlam
4 Replies

5. Shell Programming and Scripting

something is causing this script to break early on

I am relatively new at scripting in linux. Most of my scripting knowledge comes from doing batch scripting in windows. Anyway, I have this script I'm trying to write that will install a program called Nagios along with a few other packages. I know it has to be something at the beginning that is... (4 Replies)
Discussion started by: nanite51
4 Replies

6. UNIX Desktop Questions & Answers

Create/remove desktop short cuts via command line RHEL 6.3....

I would like to write a script that would remove and/or create shortcuts in Gnome desktop in RHEL 6.3... I googled all over the place could never find what I needed... Any help would be greatly appreciated! Thank you! (0 Replies)
Discussion started by: ruberked
0 Replies

7. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies
All times are GMT -4. The time now is 06:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy