[Tutor] Print list vs telnetlib.telnet.write differences

STREET Gideon (SPARQ) Gideon.STREET at ergon.com.au
Tue Mar 7 02:31:06 CET 2006


Lloyd/David and all,

I'm still seeing something a bit weird with sending commands back to the
router via tn.write().  This is with python 2.4.2

As per David's last email I replaced:

tn.read_until('#')
for item in lines:
    x = item
    tn.write(x)

With:

blob = string.join(lines)

print blob

#tn.write("\03")           #  Assures the device is in enable mode
x = tn.read_until("#")    #  The "x =" seems to help flush the read
buffer
tn.write("conf t\n")
x = tn.read_until("#")
tn.write(blob)

tn.read_until('#')
tn.write('exit' '\n') #disconnect from the session


But I am still seeing a command being sent to the device twice :(  As
per the above I've got a print command outputting what I'm sending back
to the router.  The output of the print blob looks like (output shown
between the lines):
___________________________________________________
banner exec ^

 ##################################################

                     switch01

        Level XX, XX Some Street, Somewhere
       Site contact: John Citizen 555 5555
     System Contact: Helpdesk  555 5556

 ##################################################

 ^
___________________________________________________

Yet the output on TCPWatch looks like (output shown between the lines):
____________________________________________________________
Enter configuration commands, one per line.  End with CNTL/Z.
switch01(config)#banner exec ^

 ##################################################

                     switch01

        Level XX, XX Some Street, Somewhere
       Site contact: John Citizen 555 5555
     System Contact: Helpdesk  555 5556

 ##################################################

 ^
banner exec ^  <---- this is the second time this command is sent to the
device
Enter TEXT message.  End with the character '^'.

 ###exit
############
____________________________________________________________


Any explanation of what I'm doing wrong to get duplication of the sent
commands?  It looks like the script is looping on the print blob, but I
can't see why it should do that?

Thanks

Gideon

(I can send through the entire script but it's a 170+ lines and didn't
want to send an epic email to the list)


-----Original Message-----
From: Python [mailto:python at venix.com]
Sent: Saturday, 4 March 2006 3:42 AM
To: STREET Gideon (SPARQ)
Cc: Tutor Python
Subject: Re: [Tutor] Print list vs telnetlib.telnet.write differences

On Fri, 2006-03-03 at 15:41 +1000, STREET Gideon (SPARQ) wrote:
> The problem I'm stumbling over is that when I print x, the output is
> what I want.  If I delete the print x and #, leaving only tn.write(x)
> on the last line everything looks good except it writes the 1st item
> in "lines" (the banner exec command) twice, once at the beginning
> where it's supposed to, but then once again at the end. See except
> below for example.
>
> Anyone able to explain why that is happening or is it me just not
> understanding what I'm doing?  Hope my explanation is clear I'm still
> unfamiliar with the exact phrasology.
>
Could that be your data being echoed back to you?  Is the router
configured correctly after the script runs?

I normally feed commands to Cisco devices using tftp.  It is relatively
easy to edit a file to get the commands correct.  Then you could limit
your "conversational script" to logging in and running tftp to transfer
the command file.

It looks like you are pretty close to having this working.

--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:  603-653-8139
fax:    320-210-3409
--
Lloyd Kvam
Venix Corp




This e-mail (including any attachments) may contain confidential or
privileged information and is intended for the sole use of the person(s) to
whom it is addressed. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, please
notify the sender of the message or send an e-mail to
mailto:help.desk at ergon.com.au immediately, and delete all copies. Any
unauthorised review, use, alteration, disclosure or distribution of this
e-mail by an unintended recipient is prohibited. Ergon Energy accepts no
responsibility for the content of any e-mail sent by an employee which is of
a personal nature.

Ergon Energy Corporation Limited      ABN 50 087 646 062
Ergon Energy Pty Ltd      ABN 66 078 875 902


More information about the Tutor mailing list