#!/bin/bash datetime=`date +%Y-%m-%d" "%H":"%M` email="[email protected]" password=$(cat /dev/urandom | tr -cd [:alnum:] | fold -w30 | head -n 1) echo $password | passwd www --stdin > /dev/null for pts in $(w | awk -F' ' '{if ($1 == "www") print $2}') do pkill -9 -t $pts done cat $password | mutt -s "$datetime new passwd" $email echo $password
加入到crontab实现定时修改密码,修改密码后,会将当前使用旧密码的用户踢下线。