Operating System - HP-UX
1757687 Members
3071 Online
108863 Solutions
New Discussion юеВ

Changing passwd by script

 
SOLVED
Go to solution
UniRock
Regular Advisor

Changing passwd by script

Hi All,

How can I change password for any non-root users by using a script?
Basically, I want to know how can we INPUT password twice while changing password in a script.

Changing password for abcd
New password: <<===
Re-enter new password: <<===

Thanks.
7 REPLIES 7
Steven Schweda
Honored Contributor

Re: Changing passwd by script

Believe it or not, a Forum search for
keywords like, say:
change password script
might find a suggestion or two in a couple of
previous threads on this topic.
UniRock
Regular Advisor

Re: Changing passwd by script

Hi Steve,

I have already searched and came mostly across "expect". But could not get a clear picture of how to use it. Is that the only tool meant for changing password by script.

Scenario:
If I have 5 users say a,b,c,d,e; how can I change their passwords to a default one with the help of script (please ignore security concerns).
This is basically what I am looking for.

Advices will be appreciated..
VK2COT
Honored Contributor

Re: Changing passwd by script

Hello,

There are number of scripts around.

At one stage, I wrote per script to
add bulk Unix accounts (with passwords)
on Linux, HP-UX, Solaris, Tru64, and AIX.

Check it and you will get an idea how to do
what you want easily:

http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt

Cheers,

VK2COT
VK2COT - Dusan Baljevic
kobylka
Valued Contributor
Solution

Re: Changing passwd by script

Hello UniRock!

> I have already searched and came mostly across "expect".
> Is that the only tool meant for changing password by script.


To automate dialogs with text-based programs anything that can do a "popen" (or similar workaraound) will be fine.

"expect" is just one of the most popular tools to create such interfaces.

Attached is a script for "expect" that does what you need.


Kind regards,

Kobylka
James R. Ferguson
Acclaimed Contributor

Re: Changing passwd by script

Hi:

You could use the Perl script I provided in this thread to generate an encrypted password for use with 'usermod':

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1252591

Regards!

...JRF...
TTr
Honored Contributor

Re: Changing passwd by script

> how can I change their passwords to a default one

I can not post the script but I use the following two commands in it to set the password to a default one.

pw_encr=`echo "pw_def" | /usr//lbin/makekey`

/usr/sam/lbin/usermod.sam -p pw_encr username

The username can be a shell variable that is read from a file or given on the command line as $1.
UniRock
Regular Advisor

Re: Changing passwd by script

Thanks everyone....
I will try your suggestions once I get back to work and will update you.