# \[ANN\] dirwatch-0.0.3

**URL:** <https://rubytalk.org/t/ann-dirwatch-0-0-3/14231>\
**Category:** ruby-talk\
**Created:** [15 October 2004 17:24 UTC](https://rubytalk.org/t/ann-dirwatch-0-0-3/14231 "2004-10-15T17:24:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [15 October 2004 17:24 UTC](https://rubytalk.org/t/ann-dirwatch-0-0-3/14231/1 "2004-10-15T17:24:33Z")

</div>

URIS  
&nbsp;&nbsp;&nbsp;[http://raa.ruby-lang.org/project/dirwatch/](http://raa.ruby-lang.org/project/dirwatch/)  
&nbsp;&nbsp;&nbsp;[Index of /lib/ruby/dirwatch](http://www.codeforpeople.com/lib/ruby/dirwatch/)

NAME  
&nbsp;&nbsp;&nbsp;dirwatch v0.0.3

SYNOPSIS  
&nbsp;&nbsp;&nbsp;dirwatch [options]+ [directory = .] [mode = watch]

DESCRIPTTION  
&nbsp;&nbsp;&nbsp;dirwatch maintains a database that mirrors the state of a directory. when  
&nbsp;&nbsp;&nbsp;run dirwatch uses this database as reference to determine when files have  
&nbsp;&nbsp;&nbsp;been created, modified, updated, deleted, or were pre-existing and then to  
&nbsp;&nbsp;&nbsp;trigger configurable commands for those conditions.

&nbsp;&nbsp;&nbsp;mode must be one of

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create or c -\> initialize database  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;watch or w -\> maintain database and take actions  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list or l -\> dump database to stdout in yaml

&nbsp;&nbsp;&nbsp;the configuration can be specified on the command line or searched for in  
&nbsp;&nbsp;&nbsp;[".dirwatch/", "."]. if a configuration is not specified or  
&nbsp;&nbsp;&nbsp;located the builtin config is used - this should only be for testing.

&nbsp;&nbsp;&nbsp;dirwatch uses the config's enumeration of the actions to be taken when  
&nbsp;&nbsp;&nbsp;files are discovered to have been created, modified, updated, deleted or  
&nbsp;&nbsp;&nbsp;existing to determine which commands to run. the action section of the config  
&nbsp;&nbsp;&nbsp;contains subsections for each of actions created, modified, updated, deleted,  
&nbsp;&nbsp;&nbsp;and existing of the form

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commands:

> **···**
>
> -  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: echo @file  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern: .\*.txt  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: cat @file
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filters:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command : while read file;do echo $file;done  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern: .\*.exe
> 
> &nbsp;&nbsp;&nbsp;for commands the token '@file' or '$file' will be replaced with the currently  
> &nbsp;&nbsp;&nbsp;processed file and the command run iff it matches pattern. pattern is not  
> &nbsp;&nbsp;&nbsp;required, in which case the command will always be run for that action. in  
> &nbsp;&nbsp;&nbsp;order to assist programs in knowing whether they are running due a created,  
> &nbsp;&nbsp;&nbsp;modified, deleted, or existing action the environment variable  
> &nbsp;&nbsp;&nbsp;'DIRWATCH\_ACTION' will be set in the child process to contain the type of  
> &nbsp;&nbsp;&nbsp;action. additionally the environment var 'DIRWATCH\_PATH' will be set to  
> &nbsp;&nbsp;&nbsp;contain the full path to the entry in question. commands are spawned  
> &nbsp;&nbsp;&nbsp;asynchronously (all at once) and then all processes are waited.
> 
> &nbsp;&nbsp;&nbsp;filters are run in a similar fashion to commands, only instead of spawning a  
> &nbsp;&nbsp;&nbsp;process for each file in question the filter is spawned once with all files in  
> &nbsp;&nbsp;&nbsp;question on standard input. the reason for the two methods is for cases using  
> &nbsp;&nbsp;&nbsp;a command (vs. a filter) would result in 10000 very expensive processes being  
> &nbsp;&nbsp;&nbsp;spawned at once and bringing a system to it's knees. the filter can process  
> &nbsp;&nbsp;&nbsp;the list of files and, for instance, batch up commands and one big command,  
> &nbsp;&nbsp;&nbsp;run them sequentially, etc.
> 
> &nbsp;&nbsp;&nbsp;this probably sounds more complicated than it is and this is compounded by the  
> &nbsp;&nbsp;&nbsp;fact that i can't seem to write : better to just try running
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch -t
> 
> &nbsp;&nbsp;&nbsp;to view a sample config file, which should be rather self explanatory.
> 
> ENVIRONMENT  
> &nbsp;&nbsp;&nbsp;export SQLDEBUG=1 -\> cause sql debugging info to be logged
> 
> FILES  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/ -\> dirwatch data files  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/db -\> sqlite database file  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/db.schema -\> sqlite database schema  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/lock -\> sentinal lock file used for nfs safe access  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/dirwatch.conf -\> default configuration location  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/dirwatch.log -\> default log file when running under cron  
> &nbsp;&nbsp;&nbsp;directory/.dirwatch/\* -\> misc files used by locking subsystem
> 
> CONFIG  
> &nbsp;&nbsp;&nbsp;default path -\> dirwatch.conf  
> &nbsp;&nbsp;&nbsp;search path -\> [".dirwatch/", "."]
> 
> DIAGNOSTICS  
> &nbsp;&nbsp;&nbsp;success -\> $? == 0  
> &nbsp;&nbsp;&nbsp;failure -\> $? != 0
> 
> AUTHOR  
> &nbsp;&nbsp;&nbsp;ara.t.howard@noaa.gov
> 
> BUGS  
> &nbsp;&nbsp;&nbsp;\> 1 && \< 42
> 
> OPTIONS  
> &nbsp;&nbsp;&nbsp;--pattern=pattern, -p  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;watch only files matching pattern (\_\_not\_\_ shell glob)  
> &nbsp;&nbsp;&nbsp;--files\_only, -f  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore everything but files - (default directories and files)  
> &nbsp;&nbsp;&nbsp;--flat, -F  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do not recurse into subdirectories - (default recurse)  
> &nbsp;&nbsp;&nbsp;--help, -h  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this message  
> &nbsp;&nbsp;&nbsp;--verbosity=verbostiy, -v  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0|fatal \< 1|error \< 2|warn \< 3|info \< 4|debug - (default info)  
> &nbsp;&nbsp;&nbsp;--log=path, -l  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set log file - (default stderr)  
> &nbsp;&nbsp;&nbsp;--log\_age=log\_age  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;daily | weekly | monthly - what age will cause log rolling (default  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nil)  
> &nbsp;&nbsp;&nbsp;--log\_size=log\_size  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size in bytes - what size will cause log rolling (default 1mb)  
> &nbsp;&nbsp;&nbsp;--config=path, -c  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valid path - specify config file (default  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;directory/.dirwatch/dirwatch.conf)  
> &nbsp;&nbsp;&nbsp;--template=[path]  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valid path - generate a template config file in path (default stdout)
> 
> EXAMPLES
> 
> &nbsp;&nbsp;&nbsp;0) initialize a directory for watching
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir create
> 
> &nbsp;&nbsp;&nbsp;1) create a config (to edit afterwards)
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch -t \> conf && vi conf
> 
> &nbsp;&nbsp;&nbsp;2) watch a dir taking actions described in config
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir watch -c conf
> 
> &nbsp;&nbsp;&nbsp;3) watch a dir taking actions described in config, but not recursing into any  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subdirectories
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir watch -c conf --flat
> 
> &nbsp;&nbsp;&nbsp;4) watch a dir taking actions described in config, ignoring all but regular  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files (ignoring directories, device files, etc.)
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir watch -c conf --files\_only
> 
> &nbsp;&nbsp;&nbsp;5) watch a dir taking actions described in config, ignoring all entries  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(directory or file) except those that match pattern
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir watch -c conf --pattern='.(OIS|OIF)$'
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;note that the config allows a pattern to be specified for each command to be  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run; the command line switch, however, is applied before any command  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specific pattern filters - it is a pre-filter.
> 
> &nbsp;&nbsp;&nbsp;6) run using all defaults in the current directory
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch
> 
> &nbsp;&nbsp;&nbsp;7) dump contents of database in yaml format
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~ \> dirwatch dir list
> 
> &nbsp;&nbsp;&nbsp;8) crontab entry the watch a directory using config found in  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"directory/.dirwatch/dirwatch.conf". note that dirwatch uses a logfile  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of 'directory/.dirwatch/dirwatch.log' when run without a controling tty.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\*/15 \* \* \* \* /full/path/to/dirwatch /full/path/to/directory
> 
> # -a --
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > When you do something, you should burn yourself completely, like a good  
> > bonfire, leaving no trace of yourself. --Shunryu Suzuki
> 
> ===============================================================================
