From: Roland G. <RGi...@cp...> - 2002-09-05 07:48:34
|
> Sometimes it fails 1st then starts working and other times it works > and them fails, if that makes any difference (or sense...) ... > Sending '1derful\n\012' to spawn id(3) OK, that was a subtle one: you are not chomping the entered password, so when you send it, it contains TWO \n. passwd clears it's readline buffer before reading the password, but depending things beyond control, the second \n might or might not be in the buffer to be cleared. If it's not cleared, the "Repeat password" prompt returns with an empty password, which clearly does not match the first one... Just remove the "\n" from the send and it should work reliably. Hope this helps, Roland -- RGi...@cp... |
From: Walls R. W C. 75 CS/S. <Rob...@HI...> - 2002-09-09 18:18:24
|
I removed the explicitly added \n from the password ->send string. Now debug reports Sending '1derful^J' to spawn id(3) instead of the '1derful\n\012' it was sending. However, the intermittent hang still occurs. When things hang, Expect receives the password instead of 'New password'. That is: Waiting for new data ... 1derful instead of: Waiting for new data ... New password: (and THEN receiving the password from ->send) It's like the answer arrives before the question is asked... I tried chomping the input passwords, but that did no good. I am using Term::ReadKey to input the password. Could there be some buffer issues with just loading that module? I hard coded the password string "1derful\n" and did not use ReadKey at all and things seem to work consistently. I could get the password as an arg, but that puts the password on the screen. I could also use getc instead of ReadKey, but I don't know how to turn off echo. I tried system "stty cbreak </dev/tty >/dev/nul"; but that still echo'd. Anyway, I am just trying to change system and Samba passwords at the same time and do some other updates to files when I or my users change their passwords. Do you have any ideas on a better way to do this? I am sure it has been done before, and I'm not too proud to use someone else's code! Expect seems like the natural thing to use to glue things together, so maybe you've seen something like this (many times?) Thanks for the help. -----Original Message----- From: Roland Giersig [mailto:RGi...@cp...] Sent: Thursday, September 05, 2002 1:48 AM To: Walls Rob W Contr 75 CS/SCBS Cc: 'exp...@li...' Subject: RE: [Expectperl-discuss] Expect and passwd > Sometimes it fails 1st then starts working and other times it works > and them fails, if that makes any difference (or sense...) ... > Sending '1derful\n\012' to spawn id(3) OK, that was a subtle one: you are not chomping the entered password, so when you send it, it contains TWO \n. passwd clears it's readline buffer before reading the password, but depending things beyond control, the second \n might or might not be in the buffer to be cleared. If it's not cleared, the "Repeat password" prompt returns with an empty password, which clearly does not match the first one... Just remove the "\n" from the send and it should work reliably. Hope this helps, Roland -- RGi...@cp... |
From: Austin S. <te...@of...> - 2002-09-09 18:37:07
|
On Mon, Sep 09, 2002 at 12:17:41PM -0600, Walls Rob W Contr 75 CS/SCBS wrote: > I removed the explicitly added \n from the password ->send string. Now > debug reports Sending '1derful^J' to spawn id(3) instead of the > '1derful\n\012' it was sending. However, the intermittent hang still occurs. > When things hang, Expect receives the password instead of 'New password'. > That is: > Waiting for new data ... > 1derful > > instead of: > > Waiting for new data ... > New password: > It's like the answer arrives before the question is asked... Typically a well written password program, i.e. one that asks for a password, should turn echoing off before printing the 'Password: ' prompt. Some programs, such as /bin/passwd included w/ redhat 6.2, send the password prompt, and then flush the pty buffer as they set '-echo' on the line. This creates a race condition that may be experienced maybe 2-5% of the time. I would first turn on $Exp_Internal and make sure you are expecting a space after 'New password:', if one is sent. Once that is correct and you are 100% sure you're matching the correct prompt, sleep(1) before sending the password. That way you will give the program a chance to set echoing off and get ready to receive the data well before you send it. Austin |
From: Walls R. W C. 75 CS/S. <Rob...@HI...> - 2002-09-09 20:20:26
|
Hey! Sleeping for 1 sec after the spawn seems to have fixed the problem. Thanks! -----Original Message----- From: Austin Schutz [mailto:te...@of...] Sent: Monday, September 09, 2002 12:34 PM To: Walls Rob W Contr 75 CS/SCBS Cc: 'Roland Giersig'; 'exp...@li...' Subject: Re: [Expectperl-discuss] Expect and passwd On Mon, Sep 09, 2002 at 12:17:41PM -0600, Walls Rob W Contr 75 CS/SCBS wrote: > I removed the explicitly added \n from the password ->send string. Now > debug reports Sending '1derful^J' to spawn id(3) instead of the > '1derful\n\012' it was sending. However, the intermittent hang still occurs. > When things hang, Expect receives the password instead of 'New password'. > That is: > Waiting for new data ... > 1derful > > instead of: > > Waiting for new data ... > New password: > It's like the answer arrives before the question is asked... Typically a well written password program, i.e. one that asks for a password, should turn echoing off before printing the 'Password: ' prompt. Some programs, such as /bin/passwd included w/ redhat 6.2, send the password prompt, and then flush the pty buffer as they set '-echo' on the line. This creates a race condition that may be experienced maybe 2-5% of the time. I would first turn on $Exp_Internal and make sure you are expecting a space after 'New password:', if one is sent. Once that is correct and you are 100% sure you're matching the correct prompt, sleep(1) before sending the password. That way you will give the program a chance to set echoing off and get ready to receive the data well before you send it. Austin |