1833870 Members
1585 Online
110063 Solutions
New Discussion

password script

 
SOLVED
Go to solution
John Carver
Frequent Advisor

password script

I have 30 new users that I would like to set the same initial password for. I would like to accomplish this through a script. This script would contain the initial passwd and then force a change upon first login. I am not sure how to deal with the interactive prompt for password that the command passwd displays.
6 REPLIES 6
Hazem Mahmoud_3
Respected Contributor
Solution

Re: password script

The default standard for such a situation is to write an expect script. I played around with it before and it's very neat.
I'm not sure where to get it from, but do a search on "expect" in the forums and you'll find a lot of information about it.

-Hazem
RAC_1
Honored Contributor

Re: password script

You can use epect utility for this.

Aother crude method is as follows.

Prepare a list of uses in a file.

You can use usermod.sam command for this.

/usr/sam/lbin/usermod.sam -p "`echo "user_name"`|makekey" user_name.

Use this command in script and you should be done.
There is no substitute to HARDWORK
Elena Leontieva
Esteemed Contributor

Re: password script

John,

You can download the Expect program from:

http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.38/

You can find an example of automating passwd in "Unix Power Tools" book.

Elena.
Paddy_1
Valued Contributor

Re: password script

Something like this would work

-------------
#!/usr/bin/expect -f
set pass [lindex $argv 2]
spawn [lindex $argv 0] [lindex $argv 1]
expect password:
send "$pass\r"
expect password:
send "$pass\r"
expect eof
---------------
The sufficiency of my merit is to know that my merit is NOT sufficient
Patrick Ware_1
Super Advisor

Re: password script

RAC,

For some reason the script you gave isn't working for me. Could you elaborate more on what this script does?
Doug O'Leary
Honored Contributor

Re: password script

Hey;

If this is the only time you have to do something like this, you might consider using /usr/sam/lbin/usermod -p ${pwd} ${user} or /usr/sam/lbin/useradd -p ${pwd} ... ${user}

The -p options on these commands allows you to supply an encrypted password. Either add one of them or change the password of an existing user, then just copy the password into the X11 clipboard. Once done, you can loop through all the users by:

for user in $(cat ${user_file})
do
/usr/sam/lbin/usermod -p `middle_mouse_button_to_paste' ${user}
done

As far as the expect, it's very useful. I think the syntax is horrendous though so I use the expect modules with perl. great combination!

In this case, though, assuming you don't need it for anything else, it may be akin to slaying a fly with a small thermonuclear device.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html