#!/bin/bash#判断用户密码是否在警告期内#密码文件PASSFILE=/etc/shadow#判断文件是否存在if [ ! -e $PASSFILE ]; then echo "No $PASSFILE" exit 1fi#给定用户USERNAME=user1#判断用户是否存在if ! grep "^$USERNAME\>" $PASSFILE &> /dev/null; then echo "No $USERNAME" exit 1fi#密码修改时间MODDAY=`grep "^$USERNAME\>" $PASSFILE | cut -d: -f3`#密码有效期MAXDAY=`grep "^$USERNAME\>" $PASSFILE | cut -d: -f5`#过期提醒天数EXPIR=`grep "^$USERNAME\>" $PASSFILE | cut -d: -f6`#当前秒数CURRSS=`date +%s`#当前天数CURRDAY=$[$CURRSS/86400]#密码使用天数USERDAY=$[$CURRDAY-$MODDAY]if [ $[$MAXDAY-$USERDAY] -ge $EXPIR ]; then echo "No warn"else echo -e "WARN!!!\nPlease change your password as soon as possible."fi