Reports on file contents, daily

Hi.
I have a file server that among other things download some things automatically and place them in a predefined folder. However I am not the greatest at remembering to check the folder often enough to see that there are new files.

I was therefore wondering if any of you have any tips or references to scripts or programs that could check the folder for me and send me an e-mail every day or week informing me of the folders contents?
 
Or a lightweight script that you may schedule from cron(8).
Here is an example written in perl (with directory wired to . and dummy e-mail addresses):
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Mail::Sendmail;

my %config = (
                directory => '.',
                from => 'dirmonitor@fileserver',
                to => 'you@mailprovider.com'
             );

opendir(my $dir, $config{directory}) or die "Failed to open $config{directory}";
my @ls = readdir($dir);
closedir($dir);

{
        local $" = "\n";
        sendmail(
                     From => $config{from},
                     To => $config{to},
                     Subject => 'file list',
                     Message => "@ls"
                 );
}
This is just a point to start. You may want to make it configurable, error prone, order the list, add some file properties, etc.
 
Thank you izotov for that script.
It is exactly the kind of thing I was looking for. Now I can get a reminder of what is in the folder at times when I know I might have the time to deal with it. (also it is easier to remember when it's in my inbox) :e
 
Why not make it really simple?

Code:
#!/bin/sh

find /directory/to/scan/* -prune

Save it as /etc/periodic/daily/900.dirscan. See periodic(8).
 
SirDice said:
Why not make it really simple?

Code:
#!/bin/sh

find /directory/to/scan/* -prune

Save it as /etc/periodic/daily/900.dirscan. See periodic(8).
With this solution how can you specify which e-mail address to send the list of files to?
 
SirDice; your solution is just the kind of simplicity I like :)
However I feel the perl scrips is the better solution for me. It gives me a separate mail with just the information I want to see. The script is also nice for those places where now don't have root and want to monitor a folder :)
 
As with most things unix, if you ask 100 admins how to do things, you'll get 100 different solutions. Use whatever works for you ;)
 
Back
Top