Operating System - HP-UX
1752510 Members
4608 Online
108788 Solutions
New Discussion юеВ

purge mail script for HP-UX 11?

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

purge mail script for HP-UX 11?

Does anyone have a script that will purge mail that is older than a certain number of days from certain mailboxes?
5 REPLIES 5
Geoff Wild
Honored Contributor

Re: purge mail script for HP-UX 11?

If you are using mbox's - then I don't think you can...

You can zero them completely:

for i in `find / -name mbox`
do
> $i
done

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: purge mail script for HP-UX 11?

Upon further investigation - you may be able to do this with mailx...

Example:

echo "x" |mailx -u gwild
That will print a list of mail in gwild's mailbox...

If you:

echo "d *" |mailx -u gwild
That will delete all mail in gwild's mbox...


echo "x *" |mailx -u gwild|grep messages |awk '{print $2}'

will tell you how many messages are in gwild's mbox...

Say the result is 116,

echo "d 1-100" |mailx -u gwild

That will delete the first 100 messages in gwild's mbox....

man mailx for more info...

I can't see a way (yet) to do this by date...

Rgds...Geoff


Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Marvin Strong
Honored Contributor

Re: purge mail script for HP-UX 11?

you could get grepmail and try to compile it on HPUX. Personally I have never tried. I believe it takes a date.

http://grepmail.sourceforge.net/


Geoff Wild
Honored Contributor

Re: purge mail script for HP-UX 11?

oooooo...how about this:

mailx -H -u gwild |grep -v Jun |wc -l

That will tell you how many messages older then Jun (say current month)

So, a simple script:

#!/bin/sh
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "delmail \"userid\""
echo "Example:"
echo "delmail root"
exit 1
fi
echo " "

USER=$1
E=`mailx -H -u $USER |grep -v Jun |wc -l`
echo "d1-$E" |mailx -u $USER

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor
Solution

Re: purge mail script for HP-UX 11?

Added check for month:

#!/bin/sh
# script to delete mail older then current month
# gwild
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "delmail \"userid\""
echo "Example:"
echo "delmail root"
exit 1
fi

DATE=`date +%b`
USER=$1
E=`mailx -H -u $USER |grep -v $DATE |wc -l`
echo "d1-$E" |mailx -u $USER
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.