Cybersecurity
DevOps Cloud (ADM)
IT Operations Cloud
#!/bin/bash
########################################################
# dtEmailExpiredPass.sh - eMail notification about #
# expired eDirectory password #
########################################################
#
# FILE: dtEmailExpiredPass.sh
# VERSION: 0.1
# DATE: 12-25-2007
#
# AUTHOR: Denis Tomasevic
# Slovenia
#
########################################################
#############################
# Variables
#############################
# variables for eMail setup
export smtp="X.X.X.X"
export from="helpdesk@mycompany.si"
bcc="helpdesk@mycompany.si"
# variables for LDAP search
ldapHost="localhost"
ldapContext="ou=users,o=company"
ldapUser="cn=ldapproxy,o=company"
ldapPassw="secret"
checkTime="4 days"
# tmp files
tmpMsg=/tmp/passwordsToExpireMsg
tmpLdapResult=/tmp/passwordsToExpire
# calculate a time in a future
# now checkTime and transform it to LDAP format
notifyExpirationTime=`date -d"$checkTime" %Y%m�00000Z`
# search in LDAP for expired passwords,
# ignore users disabled by administrator
# store results in file tmpLdapResult
ldapsearch -x -Z -b $ldapContext -h $ldapHost \
-D $ldapUser -w $ldapPassw -LLL \
"(&(passwordExpirationTime$tmpLdapResult
# for every user with expired password and eMail attribute
for user in `fgrep mail: $tmpLdapResult | cut -f2 -d:`; do
# prepare notification message for a user
echo Your password will expire:>$tmpMsg;
# add some LDAP attributes to a message in their native format
fgrep -B1 -A2 $user $tmpLdapResult>>$tmpMsg;
echo>>$tmpMsg;
echo Please, change your password.>>$tmpMsg;
echo>>$tmpMsg;
echo Your password has to be compliant with password policy:>>$tmpMsg
echo Add your own password policy instructions here...>>$tmpMsg
echo>>$tmpMsg
echo Your support team>>$tmpMsg;
# send prepared message to user and a copy to a help desk
cat $tmpMsg | /usr/bin/nail -b $bcc \
-s "eDirectory password notification" $user;
done
#clean out temp files and finish
rm $tmpLdapResult
rm $tmpMsg
exit 0
"(&(loginGraceRemaining<=5)(!(loginDisabled=TRUE)))"