Shell script running as a daemon?

Kurt Wall kwall
Wed Jul 18 18:59:36 PDT 2007


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



More information about the Linux-users mailing list