LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-07-2009, 06:52 AM   #1
toshx
LQ Newbie
 
Registered: May 2008
Posts: 5

Rep: Reputation: 0
in need help in creating a script to search and delete big & old mails


Iam a linux newbie administrator,administering a mail server my mail store is getting bigger every day, so we made a policy that evry day we should be deleting mails larger than 10mb and older than 90 days, i need help in creating a script that should automate this process,it should also log the files deleted. thanks in advance.
 
Old 10-07-2009, 07:33 AM   #2
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Rep: Reputation: Disabled
You can use the find command to find out the files you want to delete. You can combine the options as you want. Also it would be nice to show what you have done.
 
Old 10-07-2009, 07:47 AM   #3
toshx
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
thanks for u reply

iam using this command find -size +10M -mtime +90 for searching then rm for deleting the files on by one.
 
Old 10-07-2009, 08:40 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,528
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Does that mean your question is answered, your problem solved? Or is there something more you want from us? If the first, please use "Thread tools" to mark the thread solved and if the second then please say what.
 
Old 10-07-2009, 09:22 AM   #5
toshx
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
not yet solved ,now i need i need a command that should delete all the files at once not one by one,then i need to combine this into a script.
 
Old 10-07-2009, 09:33 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,528
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by toshx View Post
not yet solved ,now i need i need a command that should delete all the files at once not one by one,then i need to combine this into a script.
What's the downside of a command that deletes them one-by-one? If you do create such a command (maybe find's xargs is what you are looking for) then copy and paste it into a file and make it executable -- there's your script. But you wanted to log the names of the files that are deleted; that's going to be a whole lot easier if you deal with the files one-by-one; then you can log that each file was deleted or deletion failed, including logging why deletion failed.
 
Old 10-07-2009, 09:59 AM   #7
adm1329
Member
 
Registered: Mar 2004
Distribution: CentOS 5
Posts: 128

Rep: Reputation: 17
Ok I think this is what you want.

You want a script to do the search, delete the file and create a log of it. It might can be done a little simpler but I can make it work with a couple of commands and a script.

First you want to capture the output of your search into a file
Code:
find -size +10M -mtime +90 > files
Then you need a script to parse the file, delete, and log the files.
Code:
#!/bin/sh
while read files
 do
rm -f $files
echo " "$files" deleted "$(date +%Y$m$d)" " >> filelog
done
Then you need to execute the script telling it to parse the files file.
Code:
./filedel < files
You could create another script that would run just the two commands you need and set it up as a cron job to run daily.

Code:
#!/bin/sh
find -size +10M -mtime +90 > files
./filedel < files
done

Just don't forget to make your scripts executable
Code:
chmod +x scriptname

Last edited by adm1329; 10-07-2009 at 10:02 AM.
 
Old 10-07-2009, 02:02 PM   #8
toshx
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thankz that has solved z problem
 
Old 10-07-2009, 02:31 PM   #9
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 36
Quote:
Originally Posted by adm1329 View Post
You could create another script that would run just the two commands you need and set it up as a cron job to run daily.
And put in a cron for automatic execution each day.
 
  


Reply

Tags
bash, scripting, searching


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
Need help creating a script to delete part of a filename Scorpuk Linux - Newbie 2 07-28-2008 10:19 AM
how to delete mails ZAMO Linux - Desktop 1 03-30-2007 11:27 AM
Creating a printer, but sending to a script & /dev/null, how to? cougar694u Linux - Software 1 09-24-2004 01:38 PM
Delete mails imsajjadali Red Hat 8 02-16-2004 12:13 AM


All times are GMT -5. The time now is 06:57 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration