No money back guarantees on this one. But I tested it on both HP-UX and SunOS and it works for me.
#! /usr/bin/ksh
# changepass --- change the user's password on a list of hosts
# perderabo 9/23/03 Version 0.0
#
# You will need to adjust HOSTLIST. You may need to adjust DELAY
# and all of section 2.
#
#
# Section 0 --- Set stuff up
HOSTLIST="test1 test2"
DELAY=3
stty -echo
print -n Enter Old Password-
read OLDPASS
print
print -n Enter New Password-
read NEWPASS
print
stty echo
USER=$(whoami)
exec 4>&1
#
# Section 1 --- Prove that we can talk with the hosts in HOSTLIST
# Part 1 --- telnet to each and touch a file
for HOST in $HOSTLIST ; do
telnet $HOST >&4 2>&4 |&
sleep $DELAY
print -p $USER
sleep $DELAY
print -p $OLDPASS
sleep $DELAY
print -p touch changepassdatafile.$HOST
sleep $DELAY
print -p exit
wait
done
#
# Section 1 --- Prove that we can talk with the hosts in HOSTLIST
# Part 2 --- Retrieve the files via ftp
ftp -nv >&4 2>&4 |&
for HOST in $HOSTLIST ; do
print -p open $HOST
print -p user $USER $OLDPASS
print -p get changepassdatafile.${HOST}
print -p close
done
print -p bye
wait
#
# Section 1 --- Prove that we can talk with the hosts in HOSTLIST
# Part 3 --- Inspect the retrieved files
errors=0
for HOST in $HOSTLIST ; do
if [[ -f changepassdatafile.${HOST} ]] ; then
echo $HOST was ok
rm changepassdatafile.${HOST}
else
echo $HOST has a problem
((errors=errors+1))
fi
done
((errors)) && exit 1
#
# Section 2 --- Change the passwords
for HOST in $HOSTLIST ; do
telnet $HOST >&4 2>&4 |&
sleep $DELAY
print -p $USER
sleep $DELAY
print -p $OLDPASS
sleep $DELAY
print -p passwd
sleep $DELAY
print -p $OLDPASS
sleep $DELAY
print -p $NEWPASS
sleep $DELAY
print -p $NEWPASS
sleep $DELAY
print -p exit
wait
done
#
# Section 3 --- Verify that the passwords were changed
# Part 1 --- Retrieve those files via ftp again
ftp -nv >&4 2>&4 |&
for HOST in $HOSTLIST ; do
print -p open $HOST
print -p user $USER $NEWPASS
print -p get changepassdatafile.${HOST}
print -p delete changepassdatafile.${HOST}
print -p close
done
print -p bye
wait
#
# Section 3 --- Verify that the passwords were changed
# Part 2 --- Inspect the retrieved files
errors=0
for HOST in $HOSTLIST ; do
if [[ -f changepassdatafile.${HOST} ]] ; then
rm changepassdatafile.${HOST}
else
echo $HOST has a problem!
((errors=errors+1))
fi
done
((errors)) && exit 1
exit 0