Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change user password through scripts

Status
Not open for further replies.
Mar 25, 2003
2
US
How to change user password through scripts in hp-ux 11.0
 
Not quite easy.
Do you want to change multiple systems password using script or local system's password using script.

in fist case:
change password in one system (which can rsh to other system as a root).
Make sure you do not have special character in root
cat /etc/passwd |grep root
V5ETRTolkjfTiQ6 (something like this then run following script)

You might want to try this script first on few systems.


#!/bin/sh

cat /dev/null > pending_systems
passwdtmp=/tmp/passwd.tmp
passwdtmp1=/tmp/passwd.tmp1

NEWPASSWD=`cat /etc/passwd | grep "^root" | awk -F: '{print $2}'`

for i in system1 system2 system3......
do
RESULT=`/etc/ping $i -n 2 | grep "packet loss" | \
awk '{print $7}' |cut -d"%" -f1`
if [ $RESULT -le 90 ]; then
alive=`remsh $i date`
if [ -z "$alive" ] ; then
echo $i
echo "system is alive but restrected to run remsh"
echo "${i} is restrected to run remsh" >> pending_systems
echo ""
else
echo "\n\n"
echo $i
# Change the password
rcp ${i}:/etc/passwd ${passwdtmp}
OLDPASSWD=`cat ${passwdtmp} | grep "^root" | awk -F: '{print $2}'`
sed s/${OLDPASSWD}/${NEWPASSWD}/ ${passwdtmp} > ${passwdtmp1}
mv ${passwdtmp1} ${passwdtmp}
Empty=`cat ${passwdtmp} | grep "^root" | awk -F: '{print $1}'`
if [ "$Empty" = root ] ; then
cat ${passwdtmp} | grep root
echo "\nIs this correct [y/n]"
read ans
if [ "$ans" = y ] ; then
rcp ${passwdtmp} ${i}:/etc/passwd
fi
else #empty
echo "${i} has problem \n"
echo "${i} has problem \n" >> pending_systems
fi #empty
fi
else #Result
echo "\n$i is not alive\n" >> pending_systems
fi
done

echo "\n\n file pending_systems has list of machines whose password is not changed"
#End of script---------------------------------------


Note: Make sure to run this script on few systems only to test first. If you mess it up you will not be able to login as root. You have to reboot the system and change the password in single user mode.

Patel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top