Operating System - HP-UX
1832592 Members
3024 Online
110043 Solutions
New Discussion

expect problems changing password

 
SOLVED
Go to solution
Mark Greene_1
Honored Contributor

expect problems changing password

I have the following expect commaned embedded within a ksh script:

reset_password() {
UNAME=$LoginID
UPASS=$NEWPASS

/usr/local/bin/expect -d < set timeout -1
match_max 100000
spawn passwd $UNAME\r
expect -exact "Changing password for testuser\r
New password: "
send "$UPASS\r"
expect "Re-enter new password:"
send "$UPASS\r"
send "exit\r"
EOF

return $?
}



I am getting this output from the expect debugger:

expect version 5.39.0
argv[0] = /usr/local/bin/expect argv[1] = -d
set argc 0
set argv0 "/usr/local/bin/expect"
set argv ""
executing commands from command file
spawn passwd testuser
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {26705}

expect: does "" (spawn_id exp6) match exact string "Changing password for testuser\r\nNew password: "? no
Invalid login name.

expect: does "Invalid login name.\r\n" (spawn_id exp6) match exact string "Changing password for testuser\r\nNew password: "? no
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Invalid login name.\r\n"
send: sending "test123\r" to { exp6 send: spawn id exp6 not open
while executing
"send "test123\r""


Looks like either a timing problem or a problem with too many or too few control characters on the "spawn" line. Can anyone tell me what to fix?

TIA
mark
the future will be a lot like now, only later
4 REPLIES 4
Mark Greene_1
Honored Contributor

Re: expect problems changing password

Back to top. I posted this late in the day yesterday and am not at all sure too many people saw this. I cannot believe I've uncovered anything unique here.

The user ID "testuser" does exist, and I can change the password for that ID interactively via sam or the commandline.

mark
the future will be a lot like now, only later
Francisco J. Soler
Honored Contributor
Solution

Re: expect problems changing password


Hi Mark, i don't know expect, but in shell script sometimes the variable name needs braces around it.

For example:
the line
spawn passwd $UNAME\r will be:
spawn passwd ${UNAME}\r

and perhaps \n instead of \r

Frank.
Linux?. Yes, of course.
Chris Wilshaw
Honored Contributor

Re: expect problems changing password

You're probably correct about the spawn line.

You should just need to use

spawn passwd $UNAME

(we use expect with some scripts via telnet using "spawn telnet $SERVER")

the "\r" is seen as a carriage return when using echo and a few other commands, but even then, it needs to be surrounded by quotes to be interpreted correctly.

You can see this behaviour using

echo "\r"

and

echo \r
Mark Greene_1
Honored Contributor

Re: expect problems changing password

Taking the \r out of the spawn statement did it, thanks guys!

mark
the future will be a lot like now, only later