HOWTO: Use filename based filters and complex commands with pipping without using external scripts

From: Jeremy Pyne <jeremy.pyne_at_gmail.com>
Date: Thu, 8 Oct 2009 16:53:16 -0400

I was looking into using incron and got it mostly configure before i found
the two following restrictions that were problematic.

Wildcard's cant be used for monitoring files such as:
/mydir/processing/file*.txt IN_CLOSE_WRITE mv $@/$# $@/../done

And comands can't be chained or piped when an event fires:
/mydir/processing IN_CLOSE_WRITE cd $@ && ../proc_file $# && rm $#

Both of these problems can be solved by writing a external bash file and
calling that instead but alas I'd prefer to not have hundreds of bash
scripts and have the same capabilities for piping and chaining that cron
has.

As it tunes out, after a few hours of screwing with it, two simple shell
scripts will solve both these problems. With those two scripts installed the
following command will work.

/mydir/processing IN_CLOSE_WRITE run filter $# ^*txt$ && cd $@ &&
../proc_file $# && rm $#

In this case the run option will pass the rest of the line on to bash for
full fledged execution. As the first step in the execution it will run the
filter operation witch will return true if the filename matches the regex
sting and continue execution or return false if not and end the command

/usr/bin/run
#!/bin/bash
eval $@

/usr/bin/filter
#!/bin/bash
if [[ "$1" =~ $2 ]]; then
    exit 0;
else
    exit 1;
fi

More details:
http://pynej.blogspot.com/2009/10/filesystem-based-events-with-incron.html

-- 
Jeremy Pyne
-- 
"Fear is the mind killer."  <Frank Herbert>
Received on Tue Jun 05 2012 - 22:14:21 CEST

This archive was generated by hypermail 2.2.0 : Tue Jun 05 2012 - 22:14:21 CEST