3
# passwd.expire.cron: sample expiry notification script for use as a cronjob
5
# Copyright 1999 by Ben Collins <bcollins@debian.org>, complete rights granted
6
# for use, distribution, modification, etc.
9
# edit the listed options, including the actual email, then rename to
10
# /etc/cron.daily/passwd
12
# If your users don't have a valid login shell (ie. they are ftp or mail
13
# users only), they will need some other way to change their password
14
# (telnet will work since login will handle password aging, or a poppasswd
15
# program, if they are mail users).
19
# should be same as /etc/adduser.conf
23
# this let's the MTA handle the domain,
24
# set it manually if you want. Make sure
25
# you also add the @ like "\@domain.com"
30
# Set the current day reference
31
$curdays = int(time() / (60 * 60 * 24));
33
# Now go through the list
35
open(SH, "< /etc/shadow");
37
@shent = split(':', $_);
38
@userent = getpwnam($shent[0]);
39
if ($userent[2] >= $LOW_UID && $userent[2] <= $HIGH_UID) {
40
if ($curdays > $shent[2] + $shent[4] - $shent[5] &&
41
$shent[4] != -1 && $shent[4] != 0 &&
42
$shent[5] != -1 && $shent[5] != 0) {
43
$daysleft = ($shent[2] + $shent[4]) - $curdays;
44
if ($daysleft == 1) { $days = "day"; } else {$days = "days"; }
45
if ($daysleft < 0) { next; }
46
open (MAIL, "| mail -s '[WARNING] account will expire in $daysleft $days' $shent[0]${MAIL_DOM}");
48
Your account will expire in $daysleft $days. Please change your password before
49
then or your account will expire
52
# This makes sure we also get a list of almost expired users
53
print "$shent[0]'s account will expire in $daysleft days\n";
56
@userent = getpwent();