Change Password In A Shell Script

Hi All,

I have a problem.

I need to write a shell script to change the password. The user may want to change his own password by this script.

He will have to provide the required 3 parameters i.e. old password, new password and retype new password as arguments in command line.

like, ./pass.sh old new new

How do I do it. I am in a fix. :frowning:

I am not allowed to use expect etc.

Please help me.

Thanks.
Asimananda

I am unclear as to why the 'passwd' command is not being used. It is executable by "users", and they can only use it to change THEIR password.

Do you want to "capture" their passwords when they change them ? [If so, WHY ?]

Please explain, because the 'passwd' command seems to be what you need (as far as I can tell).

No, it will be a generic script, root user may provide username, password and retype password as arguments to it, it will be an added thing to the script.
It may be useful in changing passwords for many users at a time.
I just wanted to know how do I automatically pass the values to interactive commands like passwd.

Thanks.
Asim

Can anyone please help me doing this?
It would be a great help for me :slight_smile:

Thanks.
Asimananda

I dont have any clue for how to do this either..but may be this is the way forward... may be someone else from the group can help u sorting out this messy script to tell how to do this :slight_smile:
#! /bin/ksh
DELAY=1
OLD="oldpasswd"
NEW="nepasswd"
passwd |&
sleep $DELAY
print -p $OLD
sleep $DELAY
print -p $NEW
sleep $DELAY
print -p $NEW

Hi,

Thanks for the reply.

But it's not working. I think some modification is required :frowning:

Let's hope we can get a solution for this.

Thanks.
Asimananda

I also tried the script but it is not working. If someone have any answeres to it please post me :frowning:

Prashant.