passwd

Dear frnds,

I have 250 users in passwd file with different passwords, how i can change the password to username+99. pls help out.

regards

cat /etc/passwd | head -100 | tail -1 && passwd <the-result>
I think this can be done with sed also.

From what I understand he doesn't want to change the password for the user who is on line 99 in the password file, but for all users in the password file he wants to set the password equal to the username added with +99.

If this is the case you have to be very carefull about it.

Do NOT change the password for system related accounts, some of them are
locked for a good reason.

Furthermore, it is not wise to set passwords to such a simple pattern, especially when your system can be reached from the outside world. Because your system will be hacked in no time.

Please clarify first if you actually want to set the password for each user to "<username>+99".

If this is the case, and it is really what you want, we can take it further from there.

Dear sb,
thanks for your query, I actually mean it, because we r just to launch the new hp ux11i. I already set a common password for all the users, but now mngmt wants to set it as username added with 99 as initial password. later they can change. pls help me out.....

regards

Like I said before, make sure you only change the passwords of "real" users and not of system related accounts.

Hopefully your "real" users are assigned a specific range for the uid (field 3 in /etc/passwd) and no other accounts have an uid within this range.

Now lets assume the uid of a "real" user is between 5000 and 7000.

Then the following script might do the job for you. The script assumes that "expect" is available on your system. You might have to replace "nawk" by "awk".

#!/usr/bin/ksh

for USER in `nawk 'BEGIN { FS=":" } { if ($3 >= 5000 && $3 <= 7000) print $1 }' /etc/passwd`
do
  expect -c "
    spawn passwd ${USER}
    expect \"New Password: \"
    send \"${USER}99\r\"
    expect \"Re-enter new Password: \"
    send  \"${USER}99\r\"
    expect eof" > /dev/null 2>&1
done

Thanks, sb008, good solution.

There is a sticky thread at the top of the HP-UX forum with a link to a freeware site. A precompiled and ready-to-install version of "expect" can be found there. On HP-UX the program called "awk" is actually "nawk" so you will need that change.

Thanks to sysgate & perdobo and special thanks to sb, I will try it in the weekend holiday.