?
Solved

Expect invalid password question - please help

Posted on 2005-03-04
19
Medium Priority
?
486 Views
Last Modified: 2013-12-26
expect {
 "\rENTER PASSWORD\r* "  { send -- "${pwd}\r" }
 -exact "NO CARRIER" abort
}

ahoffman,

You posted this script for me to try when I had an invalid password.  I've tried the following;
#!/progress/amps/ken/expect/expect-5.42/expect -f                              
                                                         
                                                                               
set dialaddress [lindex ${argv} 0]                                              
set pwd [lindex ${argv} 1]                                                      
set comd [lindex ${argv} 2]                                                    
set timeout -1                                                                  
spawn cu -l cul1p10 ${dialaddress}                                              
match_max 100000                                                                
expect -exact "Autodialing - please wait\r\r                                    
Connected\r                                                                    
 2400\r                                                                        
"                                                                               
send -- "\r"                                                                    
expect {                                        
"\rINVALID PASSWORD\r                            
TECLEE CLAVE: \r                                
ENTER PASSWORD: "                               
{ send -- "${pwd}\r"}                            
-exact "!-221,EXCESSIVE LOGIN ATTEMPTS\r" exit  
}                                                
expect -exact "\r                                
.\r                                              
* "                                             
send -- "${comd}\r"                              
expect -exact "\r                                
.\r                                              
* "                                             
send -- "bye\r"                                  
expect -exact "bye\r                            
.\r                                              
\r                                              
Logging off...\r                                
"                                               
send -- "~."                                    
expect -exact "\[bos6624\]."                    

The message I get back is the ! excessive login instead of no carrier for my example.  When I run it, it gets to the point where it asks for the password and the script just sticks there.  Also you had 'abort' and I know that that is supposed to be a script somewhere but I am C ignorant and don't know what the script contains or even where to put it.  PLEEEEAAAAASE help me.  I know I've been a pest about these expect questions but I can't help it.
0
Comment
Question by:Cherylvan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 4
19 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13462818
> .. I  know I've been a pest ..
LOL, you see we even try to help these people too ;-)

according your script: you have split the lines and they contain \r also
If you expect

"bye\r
.\r
\r"

then this means that there is a \r followed by \n, hope this is what you real expect
also keep in mind that --exact is as pedantic as the word says: exact. So enshure that you strings are exactly what you have written in your script, including *all* white spaces (space, tab, \r, \n).

BTW, you can simply test your script interactively, for example after starting expect in a shell:

expect -exact "!-221,EXCESSIVE LOGIN ATTEMPTS" { puts "ok"; }
!-221,EXCESSIVE LOGIN ATTEMPTS
0
 

Author Comment

by:Cherylvan
ID: 13462986
I found out why it was sticking, the \r I had before the INVALID PASSWORD was what was doing it.  but what it does now is come back again and reshows the prompt and sticks.   When I do it manually, I have to enter the password wrong 3 times before i get the excessive login attempts message.  What am I doing wrong?  
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13463087
>  I have to enter the password wrong 3 times ..
what do you get when your enter a correct password?
what do you get after the first wrong password?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Cherylvan
ID: 13463117
When I enter a correct password I get a * to enter my command.
If I enter the password wrong the first time I get the original prompt again
INVALID PASSWORD                            
TECLEE CLAVE:                                  
ENTER PASSWORD:

and this is where it will stick.      
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13463187
replace:

"\rINVALID PASSWORD\r                            
TECLEE CLAVE: \r                                
ENTER PASSWORD: "                               
{ send -- "${pwd}\r"}  

by:

"INVALID PASSWORD" { send -- "${pwd}\r" }  
0
 

Author Comment

by:Cherylvan
ID: 13463232
It still does the same:
spawn cu -l cul1p10 19999999999  
Autodialing - please wait        
Connected                        
 2400                            
                                 
INVALID PASSWORD                
TECLEE CLAVE:                    
ENTER PASSWORD:                  
INVALID PASSWORD                
TECLEE CLAVE:                    
ENTER PASSWORD:                  

and sticks here.

This is the code:
expect {                                        
"INVALID PASSWORD" {send -- "${pwd}\r"}          
-exact "!-221,EXCESSIVE LOGIN ATTEMPTS\r" exit  
}                                                
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13463273
damn, missing ;

"INVALID PASSWORD" {send -- "${pwd}\r"; }
0
 

Author Comment

by:Cherylvan
ID: 13463302
It still did the same thing.  Are you sick of me yet?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13463340
not sick, but sleepy and out of ideas for now ... be back tomorrow
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 13464832
Try the command
exp_internal -f <some file> 0
then do a run.
When you are finished, <some file> will contain copious output telling you what expect was looking for, and what it saw.
0
 

Author Comment

by:Cherylvan
ID: 13466090
This is what I got but I can't tell much from it. (btw I'm sending 'junk' as the password because I'm testing for invalid password)
expect: does "" (spawn_id exp4) match exact string "Autodialing - please wait\r\
r\nConnected\u0007\r\n 2400\r\n"? no                                            
Autodialing - please wait                                                      
                                                                               
expect: does "Autodialing - please wait\r\r\n" (spawn_id exp4) match exact strin
g "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\n"? no            
Connecte                                                                        
expect: does "Autodialing - please wait\r\r\nConnecte" (spawn_id exp4) match exa
ct string "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\n"? no    
d                                                                              
                                                                               
expect: does "Autodialing - please wait\r\r\nConnected\u0007\r\n" (spawn_id exp4
) match exact string "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\
n"? no                                                                          
 2400                                                                          
                                                                               
expect: does "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\n" (spaw
n_id exp4) match exact string "Autodialing - please wait\r\r\nConnected\u0007\r\
n 2400\r\n"? yes                                                                
expect: set expect_out(0,string) "Autodialing - please wait\r\r\nConnected\u0007
\r\n 2400\r\n"                                                                  
expect: set expect_out(spawn_id) "exp4"                                        
expect: set expect_out(buffer) "Autodialing - please wait\r\r\nConnected\u0007\r
\n 2400\r\n"                                                                    
send: sending "\r" to { exp4 }                                                  
                                                                               
expect: does "" (spawn_id exp4) match glob pattern "INVALID PASSWORD"? no      
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
                                                                               
INVALI                                                                          
expect: does "\r\nINVALI" (spawn_id exp4) match glob pattern "INVALID PASSWORD"?
 no                                                                            
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
D PASSWORD                                                                      
TE                                                                              
expect: does "\r\nINVALID PASSWORD\r\nTE" (spawn_id exp4) match glob pattern "IN
VALID PASSWORD"? yes                                                            
expect: set expect_out(0,string) "INVALID PASSWORD"                            
expect: set expect_out(spawn_id) "exp4"                                        
expect: set expect_out(buffer) "\r\nINVALID PASSWORD"                          
send: sending "junk\r" to { exp4 }                                              
                                                                               
expect: does "\r\nTE" (spawn_id exp4) match exact string "\r\n.\r*"? no        
CLEE CLAVE:                                                                    
ENTER PASSWORD:                                                                
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: " (spawn_id exp4) match exac
t string "\r\n.\r*"? no                                                        
                                                                               
INVALID                                                                        
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: \r\nINVALID" (spawn_id exp4)
 match exact string "\r\n.\r*"? no                                              
 PASSWORD                                                                      
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: \r\nINVALID PASSWORD\r" (spa
wn_id exp4) match exact string "\r\n.\r*"? no                                  
                                                                               
TECLEE CLAVE:                                                                  
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: \r\nINVALID PASSWORD\r\nTECL
EE CLAVE:" (spawn_id exp4) match exact string "\r\n.\r*"? no                    
                                                                               
ENTER PAS                                                                      
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: \r\nINVALID PASSWORD\r\nTECL
EE CLAVE: \r\nENTER PAS" (spawn_id exp4) match exact string "\r\n.\r*"? no      
SWORD:                                                                          
expect: does "\r\nTECLEE CLAVE: \r\nENTER PASSWORD: \r\nINVALID PASSWORD\r\nTECL
EE CLAVE: \r\nENTER PASSWORD: " (spawn_id exp4) match exact string "\r\n.\r*"? n
o                                                                              
0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 2000 total points
ID: 13467634
You should only send the password after the ENTER PASSWORD: prompt, not after you see INVALID PASSWORD. Some systems discard input just before they send this prompt. That may be all your problem is.
Thanks for posting the output - it does in fact tell you everything you need to know but it's a little hard to read at first.
The last bit tells you that the system is waiting for a password but your script is waiting for it to send \r\n.\r*. So you are stuck.  By the way it will never send you the 'exact' string \r\n.\r*. Get rid of the exact. You hardly ever want to use it
Make the above 2 changes and try it again. Post the script as well as the output if it still doesn't work.

How to read the output:-

The output is in blocks. The creation of a block is triggered by some data arriving on the line. This is shown first. Expect appends this data to data already received since the last match and then compares what it now has with what it is looking for. This is shown in the output as "expect: does ... (spawn id xxx) match {exact string|glob pattern|regular expression} ...?" The block ends with "yes" or "no", depending whether the received data matched or not.

If the block ends "yes", expect logs what it did next It sets the variable expect_out(0,string) to be the matched string. It sets the variable expect_out(spawn_id) to the process that matched the string (you only have one process). It sets expect_out(buffer) to the data that will be forgotten before doing any more matches.

After the above housekeeping, it now actually does what you told it to do on a match:
send: sending ... to xxx
0
 

Author Comment

by:Cherylvan
ID: 13470203
I didn't work.  Here's my script:
#!/progress/amps/ken/expect/expect-5.42/expect -f                            
#                                                                            
set force_conservative 1  ;# set to 1 to force conservative mode even if      
                          ;# script wasn't run conservatively originally      
if {$force_conservative} {                                                    
        set send_slow {1 .1}                                                  
        proc send {ignore arg} {                                              
                sleep .1                                                      
                exp_send -s -- $arg                                          
        }                                                                    
}                                                                            
                                                                             
set dialaddress [lindex ${argv} 0]                                            
set pwd [lindex ${argv} 1]                                                    
set comd [lindex ${argv} 2]                                                  
set timeout -1                                                                
spawn cu -l cul1p10 ${dialaddress}                                            
#exp_internal -f junk 0                                                      
match_max 100000                                                              
expect -exact "Autodialing - please wait\r\r                                  
Connected\r                                                                  
 2400\r                                                                      
"                                                                             
send -- "\r"                                        
expect {                                            
"ENTER PASSWORD:" {send -- "${pwd}\r";}            
-exact "!-221,EXCESSIVE LOGIN ATTEMPTS\r" exit      
}                                                  
expect "\r                                          
.\r*"                                              
send -- "${comd}\r"                                
expect -exact "\r                                  
.\r*"                                              
send -- "bye\r"                                    
expect -exact "bye\r"                              
send -- "~."                                        
expect -exact "\[bos6624\]."                        
send -- "\r"                                        
expect eof                                          

Here's the output:
expect: does "" (spawn_id exp4) match exact string "Autodialing - please wait\r\
r\nConnected\u0007\r\n 2400\r\n"? no                                            
Autodialing - please wait                                                      
                                                                               
expect: does "Autodialing - please wait\r\r\n" (spawn_id exp4) match exact strin
g "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\n"? no            
Connected                                                                      
                                                                               
expect: does "Autodialing - please wait\r\r\nConnected\u0007\r\n" (spawn_id exp4
) match exact string "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\
n"? no                                                                          
 2400                                                                          
                                                                               
expect: does "Autodialing - please wait\r\r\nConnected\u0007\r\n 2400\r\n" (spaw
n_id exp4) match exact string "Autodialing - please wait\r\r\nConnected\u0007\r\
n 2400\r\n"? yes                                                                
expect: set expect_out(0,string) "Autodialing - please wait\r\r\nConnected\u0007
\r\n 2400\r\n"                                                                  
expect: set expect_out(spawn_id) "exp4"                                        
 expect: set expect_out(buffer) "Autodialing - please wait\r\r\nConnected\u0007\r
\n 2400\r\n"                                                                    
send: sending "\r" to { exp4 }                                                  
                                                                               
expect: does "" (spawn_id exp4) match glob pattern "ENTER PASSWORD:"? no        
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
                                                                               
INVALI                                                                          
expect: does "\r\nINVALI" (spawn_id exp4) match glob pattern "ENTER PASSWORD:"?
no                                                                              
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
D PASSWORD                                                                      
expect: does "\r\nINVALID PASSWORD\r" (spawn_id exp4) match glob pattern "ENTER
PASSWORD:"? no                                                                  
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
                                                                               
TECLEE CLAVE                                                                    
expect: does "\r\nINVALID PASSWORD\r\nTECLEE CLAVE" (spawn_id exp4) match glob p
attern "ENTER PASSWORD:"? no                                                    
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
:                                                                              
ENTER P                                                                        
expect: does "\r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nENTER P" (spawn_id exp4)
 match glob pattern "ENTER PASSWORD:"? no                                      
"!-221,EXCESSIVE LOGIN ATTEMPTS\r"? no                                          
ASSWORD:                                                                        
expect: does "\r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nENTER PASSWORD: " (spawn
_id exp4) match glob pattern "ENTER PASSWORD:"? yes                            
expect: set expect_out(0,string) "ENTER PASSWORD:"                              
expect: set expect_out(spawn_id) "exp4"                                        
expect: set expect_out(buffer) "\r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nENTER
PASSWORD:"                                                                      
send: sending "junk\r" to { exp4 }                                              
                                                                               
expect: does " " (spawn_id exp4) match glob pattern "."? no                    
                                                                               
I                                                                              
expect: does " \r\nI" (spawn_id exp4) match glob pattern "."? no                
NVALID PASS                                                                    
expect: does " \r\nINVALID PASS" (spawn_id exp4) match glob pattern "."? no    
WORD                                                                            
TECLEE                                                                          
expect: does " \r\nINVALID PASSWORD\r\nTECLEE " (spawn_id exp4) match glob patte
rn "."? no                                                                      
CLAVE:                                                                          
EN                                                                              
expect: does " \r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nEN" (spawn_id exp4) mat
ch glob pattern "."? no                                                        
TER PASSWORD:                                                                  
expect: does " \r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nENTER PASSWORD:" (spawn
_id exp4) match glob pattern "."? no                                            
                                                                               
expect: does " \r\nINVALID PASSWORD\r\nTECLEE CLAVE: \r\nENTER PASSWORD: " (spaw
n_id exp4) match glob pattern "."? no                                          

Also, thanks for taking time out to help me.

cheryl                                                                              
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 13470432
You still have a -exact match on * starting at line 32 - that will never work.
The Cr you enter at line 24 elicits INVALID PASSWORD - is that what you intended?
You send "junk" as a password once. It prompts you again to ENTER PASSWORD. You don't send another password, instead you wait for ".", which never comes. You are stuck again.
Your expect command was:-
expect "\r                                          
.\r*"
but expect is only waiting for ".". Perhaps you confused it by breaking the line, I'm not sure. Anyway, you shouldn't terminate glob patterns with "*" - it could match an arbitrary amount of following output, some of which you might want for the next expect.
I would suggest:-
expect "\r\n.\r"

Are you still testing the invalid password path or have you moved on? If you now expect the password to be good, you should treat INVALID PASSWORD as an error.

I really urge you to try to read these output files for yourself - they tell you everything. Also type "man expect" and read it through a few times. Have you got the book "Exploring Expect" by Don Libes? Since expect is a tcl extension, have you got "Tcl and the Tk Toolkit" by John K. Ousterhout? They're all good sources of information.
0
 

Author Comment

by:Cherylvan
ID: 13470454
I've got the Expect book by O'Reilly and the Tcl and Tk Toolkit is on its way.  I'm a Progress software developer and how I got stuck with this part of the project is beyond me.  I know absolutely NOTHING about Expect.  I'm working against a very short deadline but I am going to have to learn more about Expect because I'm going to have to support it and do some future work with it too.

I am still testing the invalid password path because the script I'm using works okay with a good password but will hang for a long time if you enter a wrong one and for each state we have about 50 numbers to dial & poll each day and only a 2 hr window in which to run this before their powerweb processes start back up.  So if it hangs on an invalid password, it will eat up alot of the time and everything won't process.  The answer would be to have 'perfect' passwords but as long as you have users entering them, I have to allow for incorrect ones.
0
 

Author Comment

by:Cherylvan
ID: 13470469
Also Invalid password is something that comes up automatically when you dial in.  You get

INVALID PASSWORD
TECLEE CLAVE:  
ENTER PASSWORD:  

This just comes up automatically even when you dial-in manually.  It's just the way the program on the other side is set up.
0
 

Author Comment

by:Cherylvan
ID: 13470865
I hate to use -exact statements due to the fact that the info I receive back contains too many \r's etc and it aborts my script.  What it looks like is happening is that the password is checked and of course it is wrong and it prompts again for the password, but what it is doing is taking my next 'send' statement and sending the command and of course that's wrong too so it prompts again and then I send it 'bye' which was where it was sticking.  When I took it out of the expect line it will go all the way thru and end the job.  It never really gets to the point where you've entered too many passwords and it gives you the Excessive login error.  I hope this is making sense.  How do I keep it from going all the way thru the rest of the expect script when the password is wrong.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 13474589
You need to take action on a bad password. Since this is supplied as an argument on entry, it does no good to keep on sending it. Just try it a couple of times and if you have no luck then break the connection and move on.
What string do you expect on successful login? You should check for that before proceeding.
Keep reading that man page: the output from exp_internal tells you everything if you learn how to read it.
0
 

Author Comment

by:Cherylvan
ID: 13476973
ahoffman,

You deserted me, I'm desperate!!!!!
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question