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 # 从 1970 年 1 月 1 日 00: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