Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15175035
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-11 22:07:35

 As you know, we meet applications connection problem almost every 1 or 2 months, because some password is expired on DB server. So I want to Infra team implement a moniter scrīpt on the three servers: xxx, yyy, zzz. The scrīpt will monitor the users' passwords, if it find the passwords will expire in one week, a warning mail will be sent out.

cat <<'!' >/bin/expire.ksh
#!/usr/bin/ksh
#SECTION1 -- Please change these following UPPERCASE variables, if you need.

CC=" "
USERLIST="user1 user2 user3"

maxage=`grep -p default: /etc/security/user | awk '$1 ~ /maxage/ {print $3}'`
expiretime=`expr $maxage \* 604800` # 1 week = 604800 seconds
threshold=`expr $expiretime - 604800`
currenttime=`perl -le "print scalar time" 2>/dev/null`

#SECTION2 -- Check whether the user in USERLIST will expire.
> /tmp/expire.txt
for i in $USERLIST; do
  grep -p ^${i}: /etc/security/passwd | awk '$1 ~ /lastupdate/ {print $3}' | read lastupdate &&
  if [ $threshold -lt `expr $currenttime - $lastupdate` ]; then
    echo "  Expire time of user $i is "`perl -le "print scalar localtime($lastupdate + $expiretime)" 2>/dev/null`"." >> /tmp/expire.txt
  fi
done

#SECTION3 -- If find some user will expire, send out a mail.
if [ -s /tmp/expire.txt ]; then
  mail -s "User expire warning mail from `hostname` at `date +'%y-%m-%d %H:%M'`" -c "$CC" $SENDTO fi
!

  NOTICES:
1)The crontab could be set like this: 0  9 * * * /usr/bin/expire.ksh .
2)The owner of the file should be set to xxx. Because our team maybe need modify the UPPERCASE variables sometime.

阅读(1313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~