View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 5 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Mar 27, 2007 3:44 am 
Offline
Joined: Wed Feb 01, 2006 8:31 pm
Posts: 45
I just made a small perl script to purge the contents of my ipodfeed directory based on a certain number of days. I run it via cron (root user cron table) every day.

I hope it can be useful for someone:

Code:
#!/usr/bin/perl -w
use Fcntl ':mode';

# Files equal or older to $purgedays will be erased
$purgedays=3;

# This is the directory where you keep you'r ipod encoded files
$workdir="/myth/ipodfeed";


$purgediff=$purgedays*3600;
$now=time();

opendir(DIR,$workdir) or die "Can't Open directory: $workdir!!!";
@FILES=grep(/\.mp4$/, readdir(DIR));

foreach $file (@FILES)
{

    $filename="$workdir/$file";
    $atime = (stat($filename))[8];

    $timediff=$now - $atime;

    if ( $timediff >  $purgediff )
    {
       ($xmlfile) = split(/\./,$file);
       $xmlpath="$workdir/$xmlfile.ipod.xml";
       unlink($filename) or die "Can't delete file : $filename!";
       unlink($xmlpath) or die "Can't delete file : $xmlpath!";
    }

}




Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 5:29 pm 
Offline
Joined: Sun Nov 16, 2003 11:26 pm
Posts: 42
I have actually been looking for something like this for a while. I get alot of podcasts and video podcasts and I have been looking for a way to autodelete them. My problem is that I keep my podcasts in separate directories and this script only seems to work in the main one.

I have looked at your script and I can see how I can modify it to remove other types of files, but since I don't know anything about perl I am unable to modify it so that it Greps the files recursively.

Is it possible to make this script do this?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 7:25 am 
Offline
Joined: Sat Feb 25, 2006 6:10 am
Posts: 6
Location: Melbourne, Australia
Spud911 wrote:
since I don't know anything about perl I am unable to modify it so that it Greps the files recursively.

Is it possible to make this script do this?


grep has a "-r" switch to do recursive searches down a directory tree, so you could try adding that.

Alternatively using the 'find' command in a bash script may be easier than the above script, and will do recursive searches.

For example:

Code:
#!/bin/bash

purgedays=3

workdir="/myth/ipodfeed"

if [ ! -d "$workdir" ]; then
        echo "Can't Open directory: $workdir!!!"
        exit 0
fi

find "$workdir" -name \*.mp4 -mtime +"$purgedays" -exec rm {} \;
find "$workdir" -name \*.xml -mtime +"$purgedays" -exec rm {} \;

exit 0



Note: use the above code at your own risk!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 1:21 pm 
Offline
Joined: Wed Feb 01, 2006 8:31 pm
Posts: 45
Code:
#!/bin/bash

purgedays=3

workdir="/myth/ipodfeed"

if [ ! -d "$workdir" ]; then
        echo "Can't Open directory: $workdir!!!"
        exit 0
fi

find "$workdir" -name \*.mp4 -mtime +"$purgedays" -exec rm {} \;
find "$workdir" -name \*.xml -mtime +"$purgedays" -exec rm {} \;

exit 0


Yes this is will work also.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 2:01 pm 
Offline
Joined: Sun Nov 16, 2003 11:26 pm
Posts: 42
Thanks guys that worked great, easier for me to hack it the way I need to as well.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu