[Techtalk] script for sending mail when password about to expire
John Clarke
johnc+linuxchix at kirriwa.net
Wed Sep 15 09:39:34 EST 2004
On Tue, Sep 14, 2004 at 03:21:17 -0700, Maria McKinley wrote:
> I would like to make a script that sends a mail to users when their
> password is about to expire. In ldap the password expiration date is
> stored as days since January 1, 1970. Is there an easy way to check the
> current date in days since January 1, 1970 in a shell script? It looks
You can get the current time in seconds since 1st Jan 1970 with "date
+%s", and you can do arithmetic in bash with $((...)). This script:
#!/bin/sh
echo "The current date and time is" `date`
today=$((`date +%s` / 86400))
echo "It's $today days since 00:00:00 1-Jan-1970"
# days from 1-Jan-1970 that the password expires
expiry=12680
# calculate how many days to password expiry
days_to_expiry=$(($expiry - $today))
if [ $days_to_expiry -lt 0 ]
then
echo "Your password has expired, go away"
elif [ $days_to_expiry -eq 0 ]
then
echo "Your password expires today, change it now"
else
echo "Your password expires in $days_to_expiry days"
fi
produces this output:
The current date and time is Wed Sep 15 09:15:20 EST 2004
It's 1095203720 seconds or 12675 days since 00:00:00 1-Jan-1970
Your password expires in 5 days
Sending mail at the appropriate time is left as an exercise for the
reader :-)
Cheers,
John
--
Windows: 1, 2, 2.1, 2.3, 286, 386, 3, for Workgroups, 3.11, NT, NT 3.5,
NT 3.51, 95, NT 4, 95 OSR2, 98, 98SE, 2000, Me. Can't you appreciate the
elegant simplicity of it all?
-- Christopher Biggs
More information about the Techtalk
mailing list