前提条件,需拥有root权限
function checkPswValid(){ local users=$1 if [ "x{users}" != "x" ];then for user in ${users[*]} do local validity=9999 local expires=`chage -l ${user}|grep -e "^Password *[e|E]xpires"|awk -F ':' '{print $2}'` if [ "x$expires" == "x never" ];then expires=99991230 else expires=`date -d "${expires}" +%s` local curdate=`date +%s` validity=$[$[$expires-$curdate]/60/60/24] expires=`date -d "@${expires}" +"%Y%m%d"` fi [[ "x${expires}" != "x" ]]&& echo "pswValid_user=${user},pswValid_expires=${expires},pswValid_validity=${validity}" done fi}function main(){ echo "==pswValid(pswValid_user)" users=`cat /etc/ssh/sshd_config|grep -e "^ *AllowUsers"` if [ "x${users}" != "x" ];then users=${users/AllowUsers/} checkPswValid "${users[*]}" return 0 else groups=`cat /etc/ssh/sshd_config|grep -e "^ *AllowGroups"` if [ "x${groups}" != "x" ];then groups=${groups/AllowGroups/} for group in ${groups[*]} do gid=`grep -e "^${group}" /etc/group|awk -F ':' '{print $3}'` users=`cat /etc/passwd | grep -v "/nologin" | awk -F":" '{print $1"\t\t"$4}' | grep -w "${gid}"|awk -F ' ' '{print $1}'| tr -d ' '|tr '\n' ' '|tr '\r' ' '` checkPswValid "${users[paas]}" done else users=`cat /etc/passwd | grep -v "/nologin"|awk -F ':' '{print $1}'|tr '\n' ' '|tr '\r' ' '` checkPswValid "${users[*]}" fi fi return 0}main