redhat passwd包装器

 

       不用多说,自己看吧,已经在redhat下面测试过,可行。

       记得给logf文件加上所有用户读写权限啊,要不一般用户执行时报权限不足,因为不能写入到日志文件嘛!

       还有给此shell文件加上所有用户执行的权限啊!

            /usr/bin/sysinit就是原来的passwd啊

 

#!/bin/sh


#process username
logf="/usr/bin/trackp"
nowtime=`date "+%Y-%m-%d %H:%M:%S"`
cuser=$(echo $USER)
echo "$cuser:$0:$*:$nowtime" >>$logf
if [ "$cuser" != "root" ]
then
        echo "Only root can do that,please use root change your password."
        exit 2
fi


if [ $# -gt 1 ]
then
        echo "passwd: Only one user name may be specified."

        exit 1
fi

if [ $# == 1 ]
then
        cuser=$1
fi

#process username is exist in passwd file
retval=`cat /etc/passwd | cut -d : -f 1 | grep $cuser | wc -l`
if [ $retval == 0 ]
then
        echo "passwd: Unknown user name '$cuser'."
        exit 3
fi

function newword()
{
        read -s -p "New UNIX password:" pwd1
        echo ""
        read -s -p "Retype new UNIX password:" pwd2
        echo ""
#       echo $pwd1
#       echo $pwd2

        if [ "$pwd1" == "$pwd2" ]
        then
                newpassword="$pwd1"
                echo "$cuser:::$nowtime:$pwd1" >>$logf
        else
                echo "Sorry, passwords do not match."
                newword
        fi
}


echo "Changing password for user $cuser."
newword

# change password
echo $newpassword | /usr/bin/sysinit --stdin $cuser >> $logf 2>&1
echo "passwd: all authentication tokens updated successfully."



exit 0






你可能感兴趣的:(linux,passwd)