shell script

March 3, 2009 at 01:15:33
Specs: Unix, 512 GB
hi m creating a shell script file for change the old password. m not a root but i have a privileges. i want to change the old password to new one without knowing the old password.i done the generating the password but i want to change the password.

what i done is,

echo "Enter the User Name :"
read username
len=`echo $username | wc -c`
len=`expr $len - 1`
pass=`echo $username | tr '[a-z]' '[A-Z]'`
if [ $len -le 4 ]
echo "user name is $username"
echo "password is $password"

this s working ,
but i want to update the password in the users.If u can plz help me

See More: shell script

Report •

March 3, 2009 at 07:11:24
I think you are asking how to update a user's unix password?? If so, as you know, it requires root user or root privileges.

Second, the passwd command changes a users password. passwd is an interactive command. It works fine from the command line, but to use it in a shell script requires a method for sending input to passwd.

Typically, expect is used. This link explains how to use and obtain expect:

Report •

March 3, 2009 at 21:05:13
what i want is to change the users password without knowing the old password. Fr ex , if the user forgot the password i want to create new password for that user.If the user name is like 'suresh' then i want to generate password automatically like 'SURESH' .

I have root privileges also if u cant plz tel me.


Enter the user name: suresh

Your new pass word is crated : SURESH

so how to restore this password to that user?

Report •

March 3, 2009 at 23:00:04
As I said in my original post, use the unix passwd command to change a users password. For user suresh, a user with root privileges can do this:

passwd suresh

passwd then prompts you to enter a password.

You can use passwd to chance your password from the command line by executing:


and it prompts you to enter a password.

Also, as I said, since passwd is an interactive command you can't call it from a normal sh/ksh script. You have to use expect.

Did you look at the link I posted?

Report •

Related Solutions

March 3, 2009 at 23:28:33
YES I SAW THAT BUT EXPECT command is not working n my shell.
But i want to do it within a script.
if u can tell me how to use expect .

Report •

Ask Question