Skip to main content

Password Expiry notification for the users in zimbra 8.x within 7 Days for the email users

This Script will run as cron tab daily basis and it will alert the users for whom password is going to expire within 7 days. It will also alert admin for the users for whom password expired.


Kindly replace the domain.com with your own domain name and the  /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail  path to the actual path of postfix


#!/bin/bash
#Script for zimbra password expiry email notification.
# Meant to be performed as daily cronjob run as zimbra user. 
# redirect output to a file to get a 'log file' of sorts.

# Time taken of script;
echo "$SECONDS Started on: $(date)"
# Set variables:
# First notification in days, then last warning:
FIRST="7"
LAST="3"
# pass expiry in days, we are assuming passwd exiry is 150 Days
POLICY="150"
# Sent from:
FROM="admin@domain.com"
# Get all users - it should run once only.
USERS=$(ionice -c3 /opt/zimbra/bin/zmprov -l gaa domain.com)

#Todays date, in seconds:
DATE=$(date +%s)
# Iterate through them in for loop:
for USER in $USERS
 do
# When was the password set?
USERINFO=$(ionice -c3 /opt/zimbra/bin/zmprov ga $USER)
PASS_SET_DATE=$(echo "$USERINFO" | grep zimbraPasswordModifiedTime: | cut -d " " -f 2 | cut -c 1-8)
NAME=$(echo "$USERINFO" | grep givenName | cut -d " " -f 2)

# Make the date for expiry from now.
#echo PASS_SET_DATE is $PASS_SET_DATE
EXPIRES=$(date -d  "$PASS_SET_DATE $POLICY days" +%s)
#echo PASS_SET_DATE is $PASS_SET_DATE
#echo EXPIRES DAYS  is $EXPIRES
# Now, how many days until that?
DEADLINE=$(( (($DATE - $EXPIRES)) / -86400 ))

# Email to send to users...
SUBJECT="$NAME - Your Password will expire in $DEADLINE days"
BODY="
Hi $NAME,
Your account password will expire in "$DEADLINE" days, Please reset your password soon.
You may also enter a zimbra calendar event to remind you.
Thanks, 
 Email Admin team
"
# Send it off depending on days, adding verbose statements for the 'log'
# First warning
if [[ "$DEADLINE" -eq "$FIRST" ]]
then
echo "Subject: $SUBJECT" "$BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -f $FROM "$USER"
echo "Reminder email sent to: $USER - $DEADLINE days left" 
# Second
elif [[ "$DEADLINE" -eq "$LAST" ]]
then
echo "Subject: $SUBJECT" "$BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -f $FROM "$USER"
echo "Reminder email sent to: $USER - $DEADLINE days left"
# Final
elif [[ "$DEADLINE" -eq "1" ]]
then
    echo "Subject: $SUBJECT" "$BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -f $FROM "$USER"
echo "Last chance for: $USER - $DEADLINE days left"

# Check for Expired accounts, get last logon date add them to EXP_LIST2 every monday
elif [[ "$DEADLINE" -lt "0" ]] && [ '$(date +%a) = "Mon"' ] 
 then 
    LASTDATE=$(echo "$USERINFO" | grep zimbraLastLogonTimestamp | cut -d " " -f 2 | cut -c 1-8)
    LOGON=$(date -d "$LASTDATE")
EXP_LIST=$(echo "$USER's password has been expired for ${DEADLINE#-} day(s) now, last logon was $LOGON.")
EXP_LIST2="$EXP_LIST2 \n $EXP_LIST"

else 
# > /dev/null for less verbose logs and a list of users.
    echo "Account: $USER reports; $DEADLINE days on Password policy"
fi

# Finish for loop
done

echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"

# Send off list using hardcoded email addresses. 

EXP_BODY="
Hello Email Admin team,
This is the monthly list of expired passwords and their last recorded login date:
$(echo -e "$EXP_LIST2")
Regards,
Email Admin Team.
"
echo "Subject: List of accounts with expired passwords" "$EXP_BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -f  admin@domain.com
# Expired accts, for the log:
echo -e "$EXP_LIST2"

echo "finished in $SECONDS seconds"
echo "Thank you"

Comments

Popular posts from this blog

SCRIPT TO SHOW INVALID LOGIN ATTEMPTS IN RED COLOR AND VALID LOGIN IN GREEN COLOR FOR ZIMBRA 8.x

Create a File by using #vi /usr/bin/watchaudit with the following contents  tail -f /opt/zimbra/log/audit.log | awk '   /INFO/ {print "\033[32m" $0 "\033[39m"}   /WARN/ {print "\033[31m" $0 "\033[39m"} ' Close and Save the File. Run the Watchaudit File in SSH Console . #chmod +x /usr/bin/watchaudit #/usr/bin/watchaudit

How DNS Works ? How Query works -Recursive and Iterative Queries for DNS Server

How DNS Works ? A DNS domain name is used in a program on the local computer. The request is then passed to the DNS Client service for resolution using locally cached information. If the queried name can be resolved, the query is answered and the process is completed. The local resolver cache can include name information obtained from two possible sources: If a Hosts file is configured locally, any host name-to-address mappings from that file are preloaded into the cache when the DNS Client service is started. For linux /unix the file is # vi /etc/hosts For windows :   c:\Windows\System32\drivers\etc The file is hosts Resource records obtained in answered responses from previous DNS queries are added to the cache and kept for a period of time. If the query does not match an entry in the cache, the resolution process continues with the client querying a DNS server to resolve the name. The cache can be cleared using the comm...