#!/bin/bash
#添加计划任务
#mkdir -p /scripts/
#touch /scripts/Passwd_expire_check.sh
#vim /scripts/Passwd_expire_check.sh
#chmod 755 /scripts/Passwd_expire_check.sh
#vim /scripts/Passwd_expire_check.sh
#01 00 * * * /scripts/Passwd_expire_check.sh
#define script content
userlist=`cat /etc/passwd |grep "/bin/bash"|awk -F ":" '{print $1}'`
count=0
sed -i '/^T/d' /etc/motd
for i in $userlist ; do
lastupdate=`grep ^$i: /etc/shadow |awk -F: '{print $3}'`
indate=`grep ^$i: /etc/shadow |awk -F: '{print $5}'`
curren_days=`date +%s |awk '{print int($1/86400)}'`
if [[ $indate == "" || $indate == 99999 ]];then
count=`expr $count + 1`
else
threshold=`expr $indate + $lastupdate - $curren_days`
if [[ 2 -le $threshold && $threshold -le 10 ]]
then
echo -e "The password for user \033[31m\"$i\"\033[0m will expire \033[32min\033[0m \033[31m$threshold\033[0m days,Please change !" >> /etc/motd
#echo -e "The \033[32m$(hostname)\033[0m user \033[31m$i\033[0m password has \033[31m$threshold\033[0m expire,please change !" |mail -s "Password alarm!" 123456@qq.com
elif [[ $threshold -eq 1 || $threshold -eq 0 ]]
then
echo -e "The password for user \033[31m\"$i\"\033[0m will expire \033[32min\033[0m \033[31m$threshold\033[0m day,Please change !" >> /etc/motd
elif [[ $threshold -lt 0 ]];then
threshold_n=`echo $threshold|awk -F- '{print $2}'`
echo -e "The password for user \033[31m\"$i\"\033[0m expired \033[32mout\033[0m \033[31m$threshold_n\033[0m days,Please change !" >> /etc/motd
fi
fi
done
shell 密码过期检测脚本
原创文章标签 shell 用户密码过期检测 文章分类 数字化转型
©著作权归作者所有:来自51CTO博客作者lyitt1987的原创作品,请联系作者获取转载授权,否则将追究法律责任
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
shell脚本检测服务
本文主要简单介绍怎么实现用计划任务来执行shell脚本并检测服务是否正常运行!
检测 服务 是否正常 启动脚本