Hi
I have a root script which is setting up user and his dirs and so on. After I create user and set up all the necessary I have to manually set user password. I try all possible ways what google find me and nothing works for me. If maybe one of you have a solution for my problem it will be great.
--stdin, echo -e, expect is not installed and we cannot use it.... nothing works
so if anyone have any idea please let me know...
We are using Solaris 10,
The following is pasted from various scripts, use it with care!
PATH=/bin:/usr/bin:/usr/sbin:/usr/sfw/bin:/opt/csw/bin
export PATH
# Solaris has no tool to set a password non-interactively.
# Using "expect" has many risks. So we directly edit /etc/shadow.
sol_pwd()
{
ETCSHADOW=/etc/shadow
DATECHG=`perl -e 'print int time/86400'`
# Backup with owner/permission
if
cp -p ${ETCSHADOW} ${ETCSHADOW}- &&
cp -p ${ETCSHADOW} ${ETCSHADOW}.aux &&
# Overwrite the files; owner/permission and line order remains
awk '
BEGIN { FS=OFS=":" }
($1==user) { $2=hash; $3=datechg }
{ print }
' user="$ID" hash="$HASH" datechg="$DATECHG" < ${ETCSHADOW} > ${ETCSHADOW}.aux
then
# *LK* in pw-hash and 0 in lastchg was overwritten. passwd -u is not necessary
mv -f ${ETCSHADOW}.aux ${ETCSHADOW}
fi
} # sol_pwd
# main
echo "Enter user:"
read ID
echo "Enter pw:"
read PASS
if [ -z "$ID" ] || [ ${#PASS} -lt 3 ]
then
exit
fi
HASH=`echo "${PASS}" | openssl passwd -stdin` || exit
sol_pwd