# Reports on file contents, daily



## crazychip (Jul 15, 2012)

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?


----------



## shitson (Jul 15, 2012)

/usr/ports/security/tripwire could be of use here.


----------



## izotov (Jul 16, 2012)

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):

```
#!/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.


----------



## crazychip (Jul 17, 2012)

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


----------



## SirDice (Jul 17, 2012)

Why not make it really simple?


```
#!/bin/sh

find /directory/to/scan/* -prune
```

Save it as /etc/periodic/daily/900.dirscan. See periodic(8).


----------



## izotov (Jul 17, 2012)

SirDice said:
			
		

> Why not make it really simple?
> 
> 
> ```
> ...


With this solution how can you specify which e-mail address to send the list of files to?


----------



## SirDice (Jul 17, 2012)

Because periodic(8) runs as root the output will be mailed to root. Same as the other periodic(8) scripts.

You can edit /etc/aliases to send root's mail elsewhere. Be sure to run newaliases(1) after you've edited the file.


----------



## crazychip (Jul 17, 2012)

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


----------



## SirDice (Jul 18, 2012)

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


----------

