Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to purge /var/mail/oracle

Posted on 2011-02-18
1
Medium Priority
?
970 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
[X]
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
1 Comment
 
LVL 8

Accepted Solution

by:
point_pleasant earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

604 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