Solved

How to purge /var/mail/oracle

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now