Script error

Hi, i got this script.. to let one user (not root), to "su" another user and change his password. but it doesn't work well. it asks to enter the new password, then, re-enter de new password, then it asks again to change the password... (he asks twice) and , it only has to ask once

Any ideas???

# Get USER
while [[ -z ${user} ]];
do
read user?"Enter User: "
done
su - $user -c passwd

Hi.

If you are not root, you cannot do it without entering the old password.

But as you need to know the password to use su to switch to the user, where is the problem?

the problem is that it asks me to change the password twice, I don't know why... it seems like it is executing the command "password" twice.

Hmm.

Which OS as you using?

For me, Solaris won't even allow passwd from su, and from CentOS it works fine:

Solaris:

Enter User: test1
Password:
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
passwd: Changing password for scott
Permission denied

CentOS:

Enter User: test1
Password: 
Changing password for user test1.
Changing password for test1
(current) UNIX password: 
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

You have to enter the old password at least twice. Once for the su, and the other for the passwd command.

Perhaps your OS is just doing it in a different order.

I'm using AIX5.3..

OK, I can test that.

I'll post the result here, when I have.

---------- Post updated at 08:17 PM ---------- Previous update was at 08:03 PM ----------

I have tested it on AIX 5.3 (TL8), with no problems:

Enter User: test1
test1's Password:
Changing password for "test1"
test1's Old password:
test1's New password:
Enter the new password again:
#