Operating System - HP-UX
1825771 Members
2171 Online
109687 Solutions
New Discussion

Is possible to pass parameters to passwd command?

 
Carme Torca
Super Advisor

Is possible to pass parameters to passwd command?

Hi,

I would like if its possible to pass one parameter to the passwd command.

The idea its to make one script passwd-chg (for example), and pass the name of the user to change and the new-passwd.... and the script will change it.... this is necessary because of I have one application that need to do that.
Does anyone if it is possible??

# passwd user < passwd1 passwd1 doesn't works ok.

Thanks very much.
Carmen.
Users are not too bad ;-)
3 REPLIES 3
Jeff_Traigle
Honored Contributor

Re: Is possible to pass parameters to passwd command?

Not directly.

If it's an untrusted system, you can use /usr/lbin/makekey to create the hashed password that you can pass to /usr/sam/lbin/usermod.sam. Here's a start for what it would look like in your script:

#!/usr/bin/sh
set -A SEED A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

USERNAME=$1
PASSWORD=$2
PASSWORD=$(echo ${PASSWORD} | grep "^[A-z0-9]\{8\}$")
SEEDIDX1=$((${#SEED[*]}*${RANDOM}/32767))
SEEDIDX2=$((${#SEED[*]}*${RANDOM}/32767))

if [ -n "${PASSWORD}" ]
then
KEY=${PASSWORD}${SEED[${SEEDIDX1}]}${SEED[${SEEDIDX2}]}
fi

UHASHPW="$(echo ${KEY} | /usr/lbin/makekey)"

/usr/sam/lbin/usermod.sam -p ${UHASHPW} ${USERNAME}
#############################################

If you're on a trusted system, I don't know that there's a similar utility to makekey that would generate an appropriate hash.
--
Jeff Traigle
Steven E. Protter
Exalted Contributor

Re: Is possible to pass parameters to passwd command?

Shalom,

Here is how I would handle this.

vi list


add to it

user1
user2
user3

while read -r username
do
passwd $username
# insert code to do other things like change password without keyboard input.
done< list

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Is possible to pass parameters to passwd command?

# insert code to do other things like change password without keyboard input.

In general I've heard this means you need to use expect or set up a pipe.