Solved

How to purge /var/mail/oracle

Posted on 2011-02-18
1
944 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

685 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