Operating System - HP-UX
1832941 Members
2544 Online
110048 Solutions
New Discussion

Script for changing root passwd

 
Marcia Ferreira_5
Occasional Contributor

Script for changing root passwd

Hi

I'm trying to change root passwd (I have many HP servers), using vipw:
#!/usr/bin/sh
export NEW=$(cat /tmp/pas) #this file contains a crypt passwd
vipw << EOF
/^root:
f:lct:$NEW^[x!
EOF

the problem is when I execute this script - error message: Input read error ...

any hints ?

rgs
Marcia Ferreira
5 REPLIES 5
Cheryl Griffin
Honored Contributor

Re: Script for changing root passwd

The problem is that vipw (vi, etc.) is interactive and not designed to run in a script.

Try usermod.sam instead.
# /usr/sam/lbin/usermod.sam -F -p encrypted_passwd root

Personally I think changing root password from a script is a dangerous thing to do.
"Downtime is a Crime."
D Block 2
Respected Contributor

Re: Script for changing root passwd

seems vipw or like vi reads from tty device in screen mode which might be un-cooked or RAW.

I know you can use ":" for ex(1) mode within
vi or vipw.


might want to test this script out using something other than root login.

best of luck
Golf is a Good Walk Spoiled, Mark Twain.
RAC_1
Honored Contributor

Re: Script for changing root passwd

You will not be able to do it with vi/vipw.

As told you have option of using
/usr/sam/lbin/sam.usermod -p "ebcrypted_pass" root

echo "anil1234te"|/usr/lbin/makekey Will give you the encrypted password. the first 8 chars is a password and last two chars are salt.

The other option is to use expect. Get it here.

http://hpux.connect.org.uk

Anil
There is no substitute to HARDWORK
Sundar_7
Honored Contributor

Re: Script for changing root passwd

vipw is meant to be an interactive stream-based editor.

if I can guess it right, it is nothing more than a wrapper to vi, with some additional code for lock/temp file creation, etc.

If you already have the encrypted password, you can try something like this

#!/usr/sbin/sh
NEW_PASS=$(cat /tmp/pas)
cp /etc/passwd /etc/passwd.save
awk -F: -v PASS=$NEW_PASS '$1 ~ /root/ {OFS=":";$2=PASS; print}' /etc/passwd.save > /etc/passwd

Learn What to do ,How to do and more importantly When to do ?
Sundar_7
Honored Contributor

Re: Script for changing root passwd

Marcia, Sorry please ignore my last message !!

This will work

#!/usr/bin/sh
NEW_PASS=$(cat /tmp/pas)
awk -F: -v PASS=$NEW_PASS '{if ($1 == "root") {OFS=":";$2=PASS;print} else print }' /etc/passwd.save > /etc/passwd
Learn What to do ,How to do and more importantly When to do ?