<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.qmailtoaster.org:80/index.php?action=history&amp;feed=atom&amp;title=Automatic_account_expirations</id>
	<title>Automatic account expirations - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.qmailtoaster.org:80/index.php?action=history&amp;feed=atom&amp;title=Automatic_account_expirations"/>
	<link rel="alternate" type="text/html" href="http://wiki.qmailtoaster.org:80/index.php?title=Automatic_account_expirations&amp;action=history"/>
	<updated>2026-04-07T18:53:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>http://wiki.qmailtoaster.org:80/index.php?title=Automatic_account_expirations&amp;diff=134&amp;oldid=prev</id>
		<title>Ebroch: Created page with &quot;== Information == From: http://www.mail-archive.com/qmailtoaster-list@qmailtoaster.com/msg16395.html  Below is a script to delete in-active account autimaticaally deleted from system. When I say in-active, it look from table vpopmail.lastauth.  It&#039;s very suitable for enterprise/business mailserver which has many employees and maybe some of them are contract employees with medium turnover, and lacks of IT resource. And may not for ISP / Hosting company which has paying cu...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.qmailtoaster.org:80/index.php?title=Automatic_account_expirations&amp;diff=134&amp;oldid=prev"/>
		<updated>2024-03-16T16:28:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Information == From: http://www.mail-archive.com/qmailtoaster-list@qmailtoaster.com/msg16395.html  Below is a script to delete in-active account autimaticaally deleted from system. When I say in-active, it look from table vpopmail.lastauth.  It&amp;#039;s very suitable for enterprise/business mailserver which has many employees and maybe some of them are contract employees with medium turnover, and lacks of IT resource. And may not for ISP / Hosting company which has paying cu...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Information ==&lt;br /&gt;
From: http://www.mail-archive.com/qmailtoaster-list@qmailtoaster.com/msg16395.html&lt;br /&gt;
&lt;br /&gt;
Below is a script to delete in-active account autimaticaally deleted from system. When I say in-active, it look from table vpopmail.lastauth.&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s very suitable for enterprise/business mailserver which has many employees and maybe some of them are contract employees with medium turnover, and lacks of IT resource. And may not for ISP / Hosting company which has paying customer whose never login.&lt;br /&gt;
&lt;br /&gt;
== Important Note ==&lt;br /&gt;
This script has 2 bugs/holes in it and I dont know how to solve it automatically:&lt;br /&gt;
&lt;br /&gt;
1. If you create a new account and the user never use it, the data won&amp;#039;t be available at table vpopmail.lastauth, so the account won&amp;#039;t be deleted.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Manual fix:&amp;#039;&amp;#039;&amp;#039; After you create new account, login to webmail to test/verify the new account working and to insert data automatically to&lt;br /&gt;
table vpopmail.lastauth.&lt;br /&gt;
&lt;br /&gt;
2. If the user resigned, but he still remember credentials (url/server,user,pass) s/he may still using the account which causing&lt;br /&gt;
the account active and won&amp;#039;t be deleted.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Manual fix:&amp;#039;&amp;#039;&amp;#039; Inform your HR/Account Dept to notify you any resigned user, so you can deleted it manually or change the password.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
# Copy the script into a file&lt;br /&gt;
# Chmod +x accountexpiration.sh&lt;br /&gt;
# Added into crontab (daily/weekly/monthly)&lt;br /&gt;
&lt;br /&gt;
== The Scripts ==&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
&lt;br /&gt;
 # Automatic Account Expiration&lt;br /&gt;
 # deleting user email after some period of time inactivity&lt;br /&gt;
 # (whose never check email via pop3 / imap3)&lt;br /&gt;
 # ver 0.1&lt;br /&gt;
 # Nov 28, 2007 &lt;br /&gt;
 # PakOgah &amp;lt;pakogah@pala.bo-tak.info&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # === Variables need to be edited ===&lt;br /&gt;
 # Exclude some users from deleting (postmaster will be a good one)&lt;br /&gt;
 # Otherwise all users will be checked&lt;br /&gt;
 # separate with space&lt;br /&gt;
 #EXCLUDED_USERS=&amp;quot;&amp;quot;&lt;br /&gt;
 EXCLUDED_USERS=&amp;quot;postmaster spam notspam pakogah&amp;quot;&lt;br /&gt;
 # List of domains you want to include / exclude from search&lt;br /&gt;
 # separate with space&lt;br /&gt;
 # empty meant all domain are included&lt;br /&gt;
 #DOMAIN_LISTS=&amp;quot;&amp;quot;&lt;br /&gt;
 DOMAIN_LISTS=&amp;quot;pala.bo-tak.info&amp;quot;&lt;br /&gt;
 # Are above Domain(s) included on search ?&lt;br /&gt;
 DOMAIN_INCLUDED=&amp;quot;Y&amp;quot;&lt;br /&gt;
 #DOMAIN_INCLUDED=&amp;quot;N&amp;quot;&lt;br /&gt;
 # If records found delete record ?&lt;br /&gt;
 # WARNING: NO Prompt is asked&lt;br /&gt;
 #EXECUTE_DELETE=&amp;quot;Y&amp;quot;&lt;br /&gt;
 EXECUTE_DELETE=&amp;quot;N&amp;quot;&lt;br /&gt;
 # Delete account after x days of inactivity&lt;br /&gt;
 DAYS=&amp;quot;180&amp;quot;&lt;br /&gt;
 # Email you the report ? If yes, then enter your email address&lt;br /&gt;
 # leave blank for not sending the report&lt;br /&gt;
 EMAIL_REPORT=&amp;quot;[EMAIL PROTECTED]&amp;quot;&lt;br /&gt;
 #EMAIL_REPORT=&amp;quot;&amp;quot;&lt;br /&gt;
 # vpopmail connection&lt;br /&gt;
 # Mysql host&lt;br /&gt;
 MYSQL_HOST=&amp;quot;localhost&amp;quot;&lt;br /&gt;
 # Mysql username&lt;br /&gt;
 MYSQL_USERNAME=&amp;quot;vpopmail&amp;quot;&lt;br /&gt;
 # Mysql password&lt;br /&gt;
 MYSQL_PASSWORD=&amp;quot;SsEeCcRrEeTt&amp;quot;&lt;br /&gt;
 #  Mysql database&lt;br /&gt;
 MYSQL_DATABASE=&amp;quot;vpopmail&amp;quot;&lt;br /&gt;
 # Verbose ? (output emailaddress to stdout for checking)&lt;br /&gt;
 VERBOSE=&amp;quot;Y&amp;quot;&lt;br /&gt;
 #VERBOSE=&amp;quot;N&amp;quot;&lt;br /&gt;
 # === Stop editing ===&lt;br /&gt;
 # === script parameter ===&lt;br /&gt;
 SYSDATE=`date +%Y%m%d`&lt;br /&gt;
 HUMANDATE=`date &amp;#039;+%b %d, %Y&amp;#039;`&lt;br /&gt;
 QMAILDEL=&amp;quot;/home/vpopmail/bin/vdeluser&amp;quot;&lt;br /&gt;
 MYSQLCLIENT=&amp;quot;/usr/bin/mysql&amp;quot;&lt;br /&gt;
 GREP=&amp;quot;/bin/grep&amp;quot;&lt;br /&gt;
 GAWK=&amp;quot;/bin/gawk&amp;quot;&lt;br /&gt;
 RM=&amp;quot;/bin/rm&amp;quot;&lt;br /&gt;
 MAIL=&amp;quot;/bin/mail&amp;quot;&lt;br /&gt;
 TMPFILE=&amp;quot;/tmp/$SYSDATE.log&amp;quot;&lt;br /&gt;
 SUBJECT=&amp;quot;Account(s) expired due $DAYS days of inactivity per $HUMANDATE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # construct SQL &lt;br /&gt;
 SQL_QUERY=&amp;quot;select concat_ws(&amp;#039;@&amp;#039;,user,domain) as email from lastauth where timestamp &amp;lt; UNIX_TIMESTAMP(SUBDATE(CURDATE(), INTERVAL $DAYS DAY))&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 if [ ! &amp;quot;$EXCLUDED_USERS&amp;quot; = &amp;quot;&amp;quot; ]&lt;br /&gt;
 then&lt;br /&gt;
        count=0&lt;br /&gt;
        for i in $EXCLUDED_USERS&lt;br /&gt;
        do&lt;br /&gt;
            count=$((count + 1))&lt;br /&gt;
        done&lt;br /&gt;
        SQL_QUERY=&amp;quot;$SQL_QUERY and&amp;quot;&lt;br /&gt;
        i=0&lt;br /&gt;
        for user in $EXCLUDED_USERS&lt;br /&gt;
        do&lt;br /&gt;
                SQL_QUERY=&amp;quot;$SQL_QUERY user&amp;lt;&amp;gt;&amp;#039;$user&amp;#039;&amp;quot;&lt;br /&gt;
                i=$((i+1))&lt;br /&gt;
                if [ &amp;quot;$i&amp;quot; -lt &amp;quot;$count&amp;quot; ]&lt;br /&gt;
                then&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY and&amp;quot;&lt;br /&gt;
                fi&lt;br /&gt;
        done&lt;br /&gt;
 fi&lt;br /&gt;
 if [ ! &amp;quot;$DOMAIN_LISTS&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
        count=0&lt;br /&gt;
        for i in $DOMAIN_LISTS&lt;br /&gt;
        do&lt;br /&gt;
            count=$((count + 1))&lt;br /&gt;
        done&lt;br /&gt;
        SQL_QUERY=&amp;quot;$SQL_QUERY and&amp;quot;&lt;br /&gt;
        if [ &amp;quot;$DOMAIN_INCLUDED&amp;quot; = &amp;quot;Y&amp;quot; ]; then &lt;br /&gt;
                SIGN=&amp;quot;=&amp;quot;&lt;br /&gt;
                if [ &amp;quot;$count&amp;quot; -eq &amp;quot;1&amp;quot; ]; then&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY domain$SIGN&amp;#039;$DOMAIN_LISTS&amp;#039;&amp;quot;&lt;br /&gt;
                else&lt;br /&gt;
                        i=0&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY (&amp;quot;&lt;br /&gt;
                        for domain in $DOMAIN_LISTS&lt;br /&gt;
                        do&lt;br /&gt;
                                SQL_QUERY=&amp;quot;$SQL_QUERY domain$SIGN&amp;#039;$domain&amp;#039;&amp;quot;&lt;br /&gt;
                                i=$((i+1))&lt;br /&gt;
                                if [ &amp;quot;$i&amp;quot; -lt &amp;quot;$count&amp;quot; ]; then&lt;br /&gt;
                                        SQL_QUERY=&amp;quot;$SQL_QUERY or&amp;quot;&lt;br /&gt;
                                fi&lt;br /&gt;
                        done&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY )&amp;quot;&lt;br /&gt;
                fi&lt;br /&gt;
        else &lt;br /&gt;
                SIGN=&amp;quot;&amp;lt;&amp;gt;&amp;quot;&lt;br /&gt;
                if [ &amp;quot;$count&amp;quot; -eq &amp;quot;1&amp;quot; ]; then&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY domain$SIGN&amp;#039;$DOMAIN_LISTS&amp;#039;&amp;quot;&lt;br /&gt;
                else&lt;br /&gt;
                        i=0&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY (&amp;quot;&lt;br /&gt;
                        for domain in $DOMAIN_LISTS&lt;br /&gt;
                        do&lt;br /&gt;
                                SQL_QUERY=&amp;quot;$SQL_QUERY domain$SIGN&amp;#039;$domain&amp;#039;&amp;quot;&lt;br /&gt;
                                i=$((i+1))&lt;br /&gt;
                                if [ &amp;quot;$i&amp;quot; -lt &amp;quot;$count&amp;quot; ]; then&lt;br /&gt;
                                        SQL_QUERY=&amp;quot;$SQL_QUERY and&amp;quot;&lt;br /&gt;
                                fi&lt;br /&gt;
                        done&lt;br /&gt;
                        SQL_QUERY=&amp;quot;$SQL_QUERY )&amp;quot;&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
 fi&lt;br /&gt;
 SQL_QUERY=&amp;quot;$SQL_QUERY;&amp;quot;&lt;br /&gt;
 #echo $SQL_QUERY&lt;br /&gt;
 # get the output&lt;br /&gt;
 $MYSQLCLIENT -u $MYSQL_USERNAME -p$MYSQL_PASSWORD -h $MYSQL_HOST &lt;br /&gt;
 $MYSQL_DATABASE -E -e &amp;quot;$SQL_QUERY&amp;quot; | $GREP email | \&lt;br /&gt;
      $GAWK -F&amp;#039; &amp;#039; &amp;#039;{print $2}&amp;#039; &amp;gt; $TMPFILE&lt;br /&gt;
 # execute it&lt;br /&gt;
 while read email&lt;br /&gt;
 do&lt;br /&gt;
        if [ &amp;quot;$VERBOSE&amp;quot; = &amp;quot;Y&amp;quot; ]; then&lt;br /&gt;
                echo &amp;quot;$email expired&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        if [ &amp;quot;$EXECUTE_DELETE&amp;quot; = &amp;quot;Y&amp;quot; ]; then&lt;br /&gt;
                $QMAILDEL $email&lt;br /&gt;
        fi&lt;br /&gt;
 done &amp;lt; $TMPFILE&lt;br /&gt;
 # report it&lt;br /&gt;
 if [ ! &amp;quot;$EMAIL_REPORT&amp;quot; = &amp;quot;&amp;quot; ]; then&lt;br /&gt;
        $MAIL -s &amp;quot;$SUBJECT&amp;quot; $EMAIL_REPORT &amp;lt; $TMPFILE&lt;br /&gt;
 fi&lt;br /&gt;
 # clean up&lt;br /&gt;
 $RM $TMPFILE&lt;/div&gt;</summary>
		<author><name>Ebroch</name></author>
	</entry>
</feed>