Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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]'`
num=123
if [ $len -le 4 ]
then
password=$pass$num
else
password=$pass
fi
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

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:

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.
ex,
Enter the user name: suresh
output:
Your new pass word is crated : SURESHso how to restore this password to that user?

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:
passwd
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?

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 .

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |