[Tutor] Matching against various login prompts

STREET Gideon (SPARQ) Gideon.STREET at ergon.com.au
Thu Mar 16 06:33:14 CET 2006


Hi again,

I'm trying to improve on couple of python scripts that I wrote and
trying to get a successful/failed login re-usable module sorted out. 

Is there any way to match a returned string against a predetermined list
of strings using the telnetlib module? I'm wanting to use a while loop
rather than an 'if ' so that I can get some error checking on the
username/password (ie typo in username). 


uPrompt = ['Username: ']
pPrompt = ['Password: ']
gPrompt = ['>']
sPrompt = ['login:']

prompt = tn.read_until('', 1)

while prompt == gPrompt:
   do stuff for device here

While prompt == uPrompt:
   do stuff for different device here

While prompt == sPrompt:
   do stuff for different OS here
   
I've tried various combinations of tn.read_until's and tn.expect's but I
don't seem to be able to capture the last line returned and match
against conditions with it.  I've read the telnetlib doco but can't
figure out which one of the many options is what I'm after (probably if
I define all the above as functions or something I could work it out but
haven't got that part straight in my head yet).

Cheers

Gideon


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