Connecting Tech Pros Worldwide Help | Site Map

find the *.log files with age and delete

Newbie
 
Join Date: Jul 2007
Posts: 1
#1: Jul 2 '07
Hi

Could help me to provide a script to find a *.log files on file name W3* and need to delete them which are older than 4 days.

(script should search entire c drive in windows with hidden files)

please mail me the script to <REMOVED BY MOD>

Thanks

lisadone
miller's Avatar
Moderator
 
Join Date: Oct 2006
Location: San Francisco, CA
Posts: 830
#2: Jul 2 '07

re: find the *.log files with age and delete


Lisa,

This site is not a code writing service. Attempt the problem yourself first. And if stuck, show us the code you have tried thus far, and people will probably be inspired to help.

- Miller
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Jul 3 '07

re: find the *.log files with age and delete


[If you are offering to pay, PM me all the details and I will PM you back a quote.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,567
#4: Jul 3 '07

re: find the *.log files with age and delete


Quote:

Originally Posted by KevinADC

[If you are offering to pay, PM me all the details and I will PM you back a quote.

He he, you beat me too it.

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#5: Jul 3 '07

re: find the *.log files with age and delete


I just love this part:

Quote:
please mail me the script to (whoever)
I'm tempted to send them something like:

Expand|Select|Wrap|Line Numbers
  1. chdir('c:\');
  2. unlink <*.*>
PS - don't try the code ;)
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,567
#6: Jul 3 '07

re: find the *.log files with age and delete


Quote:

Originally Posted by KevinADC

I just love this part:



I'm tempted to send them something like:

Expand|Select|Wrap|Line Numbers
  1. chdir('c:\');
  2. unlink <*.*>

LOL!!! THAT is too funny!!!

Quote:
PS - don't try the code ;)
Don't worry, I know what it does and I wouldn't. He he he, it would be funny though.
Newbie
 
Join Date: Jul 2008
Posts: 5
#7: Jul 16 '08

re: find the *.log files with age and delete


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. use strict;
  3. foreach (glob ("C:\\Ram\\Bangalore\\Log\\*.log"))
  4. {
  5.     my $result = -M;
  6.     if ($result > 7)
  7.     {
  8.         print "$_ is over 7 days old..removing\n";
  9.         unlink $_;
  10.     } 
  11. }
  12.  
Comments:
This script will automatically delete all log files whose age is more than 7days from the mentioned folder.

Write me for any help in C,C++,Perl,PHP and Unix related stuff. I will answer you with in the time with free of cost.

Rammohan Alampally,
HP Technologies
Bangalore
EMAIL AND URL REMOVED! AGAINST SITE POSTING POLICY
Newbie
 
Join Date: Jul 2008
Posts: 5
#8: Jul 16 '08

re: find the *.log files with age and delete


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. use strict;
  3. foreach (glob ("C:\\Ram\\Bangalore\\Log\\*.log"))
  4. {
  5.     my $result = -M;
  6.     if ($result > 4)
  7.     {
  8.         print "$_ is over 4 days old...removing\n";
  9.         unlink $_;
  10.     } 
  11. }
  12.  
Comments:
Hi Venkat,
This script will automatically delete all log files whose age is more than 4days from the mentioned folder.

Write me for any help in C,C++,Perl,PHP and Unix related stuff. I will answer you with in the time with free of cost.

Rammohan Alampally,
HP Technologies
Bangalore
EMAIL AND URL REMOVED! AGAINST SITE POSTING POLICY
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#9: Jul 16 '08

re: find the *.log files with age and delete


Quote:

Originally Posted by alampally

#!/usr/local/bin/perl
use strict;
foreach (glob ("C:\\Ram\\Bangalore\\Log\\*.log"))
{
my $result = -M;
if ($result > 4)
{
print "$_ is over 4 days old...removing\n";
unlink $_;
}
}

Comments:
Hi Venkat,
This script will automatically delete all log files whose age is more than 4days from the mentioned folder.

Write me for any help in C,C++,Perl,PHP and Unix related stuff. I will answer you with in the time with free of cost.

Rammohan Alampally,
HP Technologies
Bangalore
rammohan@india.com
www.findsyntax.com - > World's first Desktop model website (Patent under process)



This thread is more than a year old. I doubt that the OP is checking up on replies anymore. Nice of you to post a reply however.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,567
#10: Jul 16 '08

re: find the *.log files with age and delete


alampally,

I agree with Kevin, thanks for posting a solution, but the post is about a year old.


On an administrative note, I have the following to say:

1. Please use code tags when posting code in the forums. They are required and not an option. I have added them to these two posts, but this is your warning.

2. DO NOT put signatures on your posts in the forums or include email addresses or URLS (especially advertising URL's as you have done. This is your only warning of this. It is against site posting policy and will not be tolerated after the first warning.

Regards,

Jeff
Reply