很早写的,最近别人问过一次,贴出来吧。
#!/bin/bash # source /etc/profile &>/dev/null basedir=$(cd `dirname $0`;pwd) nowmonth=`date +%m` nowday=`date +%d` email="$basedir/email/sendemail.sh" function GaiMiMa() { user="$1" passwd=$(/usr/bin/mkpasswd -l 20 -d 5 -c 2 -C 4 -s 0) #mkpasswd 可以yum装下 echo $passwd | passwd --stdin $user if [ $? -eq 0 ];then sh $email "[email protected]*.com" "跳板机密码更改提示" "您的跳板机密码已经更改为: $passwd 请注意下次登录时替换此密码。【注意】不要复制空白字符;如有问题请及时找**。" echo "$user ::::: $passwd" >> $basedir/modify.log fi } grep "/bin/bash" /etc/passwd |grep -v "root"|awk -F: ‘{print $1}‘ > $basedir/userlist #user=‘yanzong.chen‘ for user in `cat $basedir/userlist` do month=$(chage -l $user | grep "Last password change"|awk -F: ‘{print $2}‘|awk ‘{print $1}‘) day=$(chage -l $user | grep "Last password change"|awk -F: ‘{print $2}‘|awk ‘{print $2}‘|tr -d ,) month=$(grep $month $basedir/month|awk -F‘=‘ ‘{print $2}‘) if [ $nowmonth -ge $month ];then D=$(expr $nowmonth \* 30 + $nowday - $day - `expr $month \* 30`) if [ $D -gt 85 ];then GaiMiMa $user fi else X=$(expr $nowmonth \* 30 + $nowday - `expr $month \* 30` - $day + 360 ) if [ $X -gt 85 ];then GaiMiMa $user fi fi done echo `date +%F` >> $basedir/modify.log
配套month文件
Jan=01 Feb=02 Mar=03 Apr=04 May=05 Jun=06 Jul=07 Aug=08 Sep=09 Oct=10 Nov=11 Dec=12
时间: 2024-10-25 03:12:51