Shell Password Expiration detection script

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.