AIX Open Source

AIX Open Source

Share your experiences and connect with fellow developers to discover how to build and manage open source software for the AIX operating system

 View Only
  • 1.  purge mails older than x days

    Posted Fri June 10, 2022 11:22 AM
    Hi all,

    how can I purge mails older than x days on AIX ?

    I want to schedule this kind of task via crontab.

    Thanks in advance for your help.

    ------------------------------
    Sylvain
    ------------------------------


  • 2.  RE: purge mails older than x days

    Posted Mon June 13, 2022 10:12 AM

    Users don't check mail on most of my systems.  I don't do it off days but do it off size.  If the mailbox is over a specific size (25000)  then purge everything except the last 1000 messages.

    cleanmailbox.sh
    ------------------------------
    #!/bin/ksh

    HOSTNAME=`hostname`

    LIST=$(find /var/spool/mail -size +25000 -ls|awk -F"/" '{print $NF}')

    for USER in $LIST; do
    echo $USER
    ls -la /var/spool/mail/$USER
    find /var/spool/mail/ -name $USER -mtime +365 -exec cp /dev/null /var/spool/mail/$USER \;
    su $USER -c /usr/local/etc/cleanmailbox.dat
    ls -la /var/spool/mail/$USER

    done


    cleanmailbox.dat
    ------------------------------
    #!/bin/ksh

    MAILCOUNT=1000

    printf "\nMail count: "
    echo f|mail|tail -1|awk '{print $2}'
    echo Cleaning Mailbox...
    echo d1-$(let num="$(echo f|mail|tail -1|awk '{print $2}')-$MAILCOUNT";echo $num)|mail >/dev/null
    printf "\nMail count: "
    echo f|mail|tail -1|awk '{print $2}'

    ------------------------------
    Vinny
    ------------------------------