Solved

How to purge /var/mail/oracle

Posted on 2011-02-18
1
930 Views
Last Modified: 2012-05-11
Hi,

I want to purge /var/mail/oracle on linux and delete messages older that 7 days. please advice.

Thanks.
sdsd2627
0
Comment
Question by:sdsd2627
1 Comment
 
LVL 8

Accepted Solution

by:
point_pleasant earned 500 total points
ID: 34928706
try this handy little perl script i wrote.  It calcualtes what the date was seven days ago, reads in the mail file specified on the command line.  searches for the first message from 7 days ago and writes from there on back into the mail box.  PLEASE BACK UP YOUR MAILBOX UNTIL YOU ARE SURE IT IS WORKING CORRECTLY, THIS WILL OVERWRITE THE MAIL FILE.  for you case you would need to run it as root or oracle.  command line execution is

perl purgemb.pl oracle

could be any user ID and you could hard code it to oracle to eliminate the need for command line arguement.


Mike

$is_found = 0;
my($day, $month, $year, $wday)=(localtime(time() - (86400*7)))[3,4,5,6];
my @mabbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @wabbr = qw( Sun Mon Tue Wed Thu Fri Sat );
$year = $year+1900;
open MAIL_FILE, "</var/mail/$ARGV[0]" or die $!;
@mail_data=<MAIL_FILE>;
close(MAIL_FILE);
foreach $line (@mail_data)
{
        if ($is_found != 1 && $line =~ /^From .*$wabbr[$day].*$mabbr[$month].*$day .*$year.*$/)
        {
                #Matched First Message from 7 days ago
                open MAIL_FILE, ">/var/mail/$ARGV[0]" or die $!;
                $is_found = 1;
        }
        if ($is_found == 1)
        {
                print MAIL_FILE $line;
        }
}
close(MAIL_FILE);

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What language/protocol is the Angular Chat? 2 73
networking details on centos 6.6 4 62
awk file 6 51
Web resource - Man pages for SUSE Enterprise Linux 11 1 22
​Being a Managed Services Provider (MSP) has presented you  with challenges in the past— and by meeting those challenges you’ve reaped the rewards of success.  In 2014, challenges and rewards remain; but as the Internet and business environment evol…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question