shell_user_login02

#!/bin/bash

userfile=/root/aa

read -p "Please input your username:" user
read -p "Please input your password:" pass

#chk_lock

if [ -z ${user} ] || [ -z ${pass} ];then
   echo "Username or Password is not allowed null"
   exit
fi

chk_user=`cat ${userfile}|awk '{print $1}'|egrep -iw ${user} |wc -l`

while read line
#for line in `cat ${userfile}`
do
    username=`echo $line |egrep -iw "${user}"|awk '{print $1}'`
    password=`echo $line |egrep -iw "${user}"|awk '{print $2}'`
    if [ ! -z ${username} ] && [ ${username} == ${user} ];then
       break
    elif [ ! -z ${user} ] && [ -z ${username} ] && [ ${chk_user} -eq 1 ] ;then
       continue
    else
       echo "Invalid username ${user}"
       exit
    fi
done < ${userfile}

if [ ${username} == ${user} ] && [ ${password} == ${pass} ];then
    echo "${username} login success"
elif [ ${username} == ${user} ] && [ ${password} != ${pass} ];then
    echo "Invalid password"
    count=0
    while [[ ${count} -lt 2 ]]
    do
       read -p "Please input your password:" pass
       if [ ${password} == ${pass} ];then
             echo "${username} login success"
             break
       else
             count=$((${count}+1))
       fi
    done
else
    echo "Invalid User ${username}"
fi
请使用浏览器的分享功能分享到微信等