#!/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 XX * * */scripts/passwd_expire_check.sh
#define Script Content
userlist= ' cat/etc/passwd |grep "/bin/bash" |awk-f ":" ' {print '} '
Count=0
Sed-i '/^t/d '/ETC/MOTD
For i in $userlist; Do
Lastupdate= ' grep ^ $i:/etc/shadow |awk-f: ' {print $} '
Indate= ' grep ^ $i:/etc/shadow |awk-f: ' {print $} '
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 would expire \033[32min\033[0m \033[31m$threshold\033[0m days,please C Hange! ">>/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!" [Email protected]
elif [[$threshold-eq 1 | | $threshold-eq 0]]
Then
ECHO-E "The password for user \033[31m\" $i \ "\033[0m would expire \033[32min\033[0m \033[31m$threshold\033[0m day,please CH Ange! ">>/ETC/MOTD
elif [[$threshold-lt 0]];then
Threshold_n= ' echo $threshold |awk-f-' {print $} '
ECHO-E "The password for user \033[31m\" $i \ "\033[0m expired \033[32mout\033[0m \033[31m$threshold_n\033[0m days,please C Hange! ">>/ETC/MOTD
Fi
Fi
Done
This article is from the "Golden mean" blog, please be sure to keep this source http://lynn1105.blog.51cto.com/2924741/1588005
Shell Password Expiration detection script