Shell script running as a daemon?

Mateus Interciso p.zarnick
Thu Jul 19 04:30:12 PDT 2007


On Wed, 18 Jul 2007 21:59:36 -0400, Kurt Wall wrote:

> On Jul 18, 2007, at 8:51 PM, Mateus Interciso wrote:
> 
>> Hello, I'm planing on making a (hopefully) simple shell script that act
>> as a daemon. This particular shell script should keep watching a
>> folder,
>> and wenever a new txt file(all files that arrive on that folder are
>> txt)
>> arrives, it should grep trough it, and take some actions. My question
>> is if it's possible to make this kind of daemon?
> 
> Sure. You're probably reinventing the wheel, but such a shell script is
> trivial to write:
> 
> --- cut here ---
> #!/bin/bash
> 
> # Create/update a sentinel file
> touch junk
> 
> # Monitor the directory
> while [ true ]; do
>          # find files newer than the sentinel file for f in `find .
>          -newer junk`; do
>                  echo $f found
>          done
>          # update the timestamp on the "sentinel" file touch junk
>          # sleep for 60 seconds
>          sleep 60
> done
> 
> --- cut here ---
> 
> YMMV. If it breaks, you get to keep both pieces.
> 
> KUrt

Kurt, thanks a lot, this will for sure help.
But why do you say that I'm reinventing the whell?
What I want is to create a daemon that keeps looking at a Maildir/cur 
folder, grep all new messages, and acording to the grep, it does some 
kind of action. I tought that a daemon was the best thing to actually do, 
but if there's other way, a bether one, please enlight me.

Mateus.




More information about the Linux-users mailing list