Linux 检测账号密码过期脚本

vi user-password-expiration-check.sh

#!/bin/sh
for user in $(cat /etc/passwd |cut -d: -f1)
do echo $user
chage -l $user | grep "Password expires"
done | paste -d " "  - - | sed 's/Password expires//g'

chmod +x user-password-expiration-check.sh

查看root的过期时间

#/bin/bash

# 从 19701100:00:00 UTC 到目前为止的秒数(时间戳)
today=$(date +%s)
expires_str=$(chage -l root|awk "NR==2"| cut -d ":" -f 2)

if [ "$expires_str" == " never" ];then
    expire_days=99999
else
    expiration=$(date -d "$expires_str" +%s)
    expire_days=$[(expiration-today)/86400]
fi

echo $expire_days

#rm -f /tmp/root_pwd_expir_days_$(date -d "-1 days" +%F).txt

#temp_file=/tmp/root_pwd_expir_days_$(date +%F).txt    
#echo $expire_days |tee $temp_file
#chown root:root $temp_file && chmod o=r $temp_file
原文地址:https://www.cnblogs.com/joshua317/p/14523678.html