[Samba] file "time-to-live"

Mike Eggleston mikeegg1 at mac.com
Tue Jun 29 08:57:53 MDT 2010


On Tue, 29 Jun 2010, Leonardo Carneiro - Veltrac might have said:

> Hi everyone,
> 
> There is a way to make files being automatically deleted some time after 
> they have been created?
> I know that, with some scripting wizardry i could achieve this, but i 
> wanna know if samba has this kind of feature.
> 
> I have a temp folder that users insist in use like a backup folder, so i 
> want to files to be deleted 24 hours after they have been created.
> 
> I cannot just delete everything at midnight because this folder is used 
> in full time, so if a user create a file at 23h59, it would be deleted a 
> minute later.
> 
> Sorry for my poor english and tks in advance.

#!/usr/bin/perl

# $Id$
# $Log$

# delete files that are 24 hours old

use Getopt::Std;
use strict;

# globals
my $dir = '/tmp';
my $oldest = time - 86400;

# get the files
opendir(DIR, $dir) or die "$0: cannot open dir '$dir': $!";
my @files = readdir(DIR);
closedir(DIR) or die "$0: cannot close dir '$dir': $!";

# decide which files to delete
my @deletefiles;
foreach my $file (@files) {
	next if $file eq '.';
	next if $file eq '..';
	next if $file eq 'lost+found';
	my @st = stat($dir . '/' . $file);
	push(@deletefiles, $file) if $st[9] < $oldest;
}

# delete the files
map { unlink($dir . '/' . $_) or warn "$0: cannot remove file '$dir/$_': $!" } @deletefiles;



More information about the samba mailing list