用户密码检查shell脚本

前端之家收集整理的这篇文章主要介绍了用户密码检查shell脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前提条件,需拥有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

原文链接:https://www.f2er.com/bash/387914.html

猜你在找的Bash相关文章