smist has asked for the wisdom of the Perl Monks concerning the following question:

Hello Great Monks, I'm trying to come up with a script that will scan a Linux file server (only certain directories) and store references to the files it finds in a database. I want to then be able to scan the same directories again (after a while) and compare the new scan with the previous scan and see the differences. The script will be used for finding filesystem changes to see where storage is being used. Can someone please share how this could be done? I've looked around and haven't found any scripts that do this yet. Thanks.

Replies are listed 'Best First'.
Re: Filesystem Scan
by derby (Abbot) on Dec 07, 2006 at 13:34 UTC

    Sounds like a tripwire type app to me.

    -derby
Re: Filesystem Scan
by dorward (Curate) on Dec 07, 2006 at 13:31 UTC

    Which bit is causing you a problem? Examining the filesystem? Storing data in a database? Scheduling the comparisons?

      I have put together a program that will scan the filesystem and store the paths to the files in a database. I am not sure about how to do the comparison. I'd like to be able to compare the scans and see where files are added.
Re: Filesystem Scan
by Firefly258 (Beadle) on Dec 07, 2006 at 16:28 UTC
    It seems to me you are looking for one of us to give you an answer when you haven't done enough research yourself. You've said you've looked around for scripts that do this, how about you look up some code that does something along these lines? Do some experimenting, trial and error, show us what code you've come up with. At the very least, show us you have made some real effort.

    Get acquainted with google and learn how to use the right terms and combinations. Google Text Searching demonstrates some simple yet powerful ways of homing in on what you need. Google Suggest supplies the most common terms people have used previously, this helps greatly if you are unfamiliar with terms, have a little trouble remembering terms, etc. Google Code Search searches for code and Perlmonk's Super Search is every perl programmer's database of information. The key to getting by in any product, be it a programming language, software application, hardware device, etc, etc is to use the right manual, find out what books or manuals are autoritative, buy them, download them, etc and start by scanning the index for what you need.

    Think about it for a second, if a file changes, just what exactly about the file changes?? How does your operating system know a file has changed? Quite obviously, more data is added to a file and therefore it's size has to change. This is a great thing to compare.

    When a file changes, the OS must keep a record of when changes were made inorder to help you know how old a file is. Therefore, modification times must have changed. Another thing to compare incase the filesize hasn't.

    I don't mean to come across as condascending with this lecture, but the best help you can get is the help you give yourself.



    perl -e '$,=$",$_=(split/\W/,$^X)[y[eval]]]+--$_],print+just,another,split,hack'er