|
Need help using expect to set password
I'm trying to do the most basic expect example but my script is not working. Here's the code:
#!/usr/local/bin/expect --
# wrapper to make passwd be noninteractive
# username is passed as 1st arg, passwd as 2nd
# Executable only by root
#added timeout to see where problem occurs
set timeout -1
spawn passwd [lindex $argv 0]
set pass [lindex $argv 1]
expect "password:"
send "$pass\r"
expect "password:"
send "$pass\r"
expect eof
#end script
Here's what happens when I run it:
[root@local root]# ./setpass test ashgt21
spawn passwd test
Changing password for user test.
New password: ashgt43
<HANGS HERE>
It looks like it is hanging expect the second password: prompt? It seems to be stuck after I sent the password the first time. Any ideas?
BTW, I can manually set the password after that script fails using the same password and user account (to rule out those 2 things as the problem):
[root@local root]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@local root]#
Any ideas on what I'm doing wrong?
|