1. Introduction

This program is written to perform the same task as the "Watched Folder" feature of Adobe Acrobat. It watches a directory for incoming files, and as soon as they are no more locked by another process it moves them into a temporary processing directory where they are processed using a specified program. After the command has finished the temporary directory is removed.

2. Details

The configuration is done via the file "/etc/watchd.conf". Please see this file for an example.
Here is a list of the parameters that are accepted anywhere. (In folders and in defaults) 

Name      | Descr.                                       | Example
----------+----------------------------------------------+------------------
dir       | Use this directory for command N.            | dir=/tmp/watchme
----------+----------------------------------------------+------------------
prg       | Process files in directory N with this cmd.  | prg=/bin/cat
----------+----------------------------------------------+------------------
uid       | Use uid for command execution (must be       | uid=1000
          | numeric) If not specified the current uid is | 
	  | used.                                        |
----------+----------------------------------------------+------------------
flags     | Use flags for this directory. Currently only | DEFAULT: 
          | the CHANGE and EXIST flags are implemented.  | flags=EXIST
----------+----------------------------------------------+------------------
logfile   | Specifies the file where watchd should log   | DEFAULT:
          | the job's outputs, if any.                   | logfile=/dev/null

The flags have the following meaning:
 
 Flag     | Behavior
----------+----------------------------------------------------------------
CHANGE    | Files are processed, when they have stopped being  
          | modified for one interval. 
----------+----------------------------------------------------------------
EXIST     | Each file that exists and is not locked
          | will be processed. (Classic behavior that is the default)
----------+----------------------------------------------------------------
COPY      | Copy the file to a temporary dir. If it is not specified
          | the file is processed "in place".
----------+----------------------------------------------------------------
DELETE    | Delete file after processing. When combined with COPY 
          | the temporary dir is also removed!
----------+----------------------------------------------------------------
SYSLOG    | Pass messages from stderr and stdout to syslog daemon
----------+----------------------------------------------------------------
MAILLOG   | Mail messages collected on stderr and stdout to a user.
          | NOT YET IMPLEMENTED!!!!!!!!!!!!!! FIX IT OR DON'T USE IT!
----------+----------------------------------------------------------------
FILELOG   | Write all messages messages collected on stderr and stdout to
          | a file
----------+----------------------------------------------------------------
ALWAYSLOG | Log always, normal behavior is to log only on return codes !=0
----------+----------------------------------------------------------------

Default is: 
flags=EXIST COPY DELETE
Which means:
All existing files are copied to a temporary directory.
Are processed there
Afterwards the files and the tempdir will be erased.

The following tags will influence all folders, so they should be set in the 
common section! But they could be set anywhere.	  
----------+----------------------------------------------+------------------
interval  | Interval in seconds for looking for new      | interval=10
          | files.                                       |
----------+----------------------------------------------+------------------
mv        | Use this program for moving the files around | DEFAULT: mv=/bin/mv
----------+----------------------------------------------+------------------
rm        | Use this program for erasing files.          | DEFAULT: rm=/bin/rm
----------+----------------------------------------------+------------------
tempdir   | Directory where to create temporary subdir-  | DEFAULT: 
          | ectories for processing the files.           | tempdir=/tmp
----------+----------------------------------------------+------------------
NOTE: "DEFAULT" means that this is the default value, if no other is specified in the configuration file. 

Here is an example chart of how the different commands are called and the according config lines and filenames.

 Config           | Command executed
------------------+-------------------------------------------------------------
tempdir=/tmp      | [N/A]
------------------+-------------------------------------------------------------
dir1=/tmp/watchme | [N/A]
------------------+-------------------------------------------------------------
mv=/bin/mv        | /bin/mv /tmp/watchme/test.gif /tmp/watchdtmp.12391
------------------+-------------------------------------------------------------
prg=/bin/cat      | /bin/cat /tmp/watchdtmp.12391/test1.gif
------------------+-------------------------------------------------------------
rm=/bin/rm        | /bin/rm -rf /tmp/watchdtmp.12391
------------------+-------------------------------------------------------------

3. Installation
Just enter "make clean" and "make all", finally "make install" as root.
It there are locked files which are processed ignoring the lock or complier errors around the area with the locking code, please uncomment the line "OPT=-DAIX" in the "Makefile"! 




