Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to purge /var/mail/oracle

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

792 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