Philip Ravenscroft on Wed, 20 Feb 2002 21:50:20 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] shell newbie has question


Sounds like a folder watcher to me.  You could write a daemon that lives in an infinite loop and forks a process or spawns a new thread when a certain condition (i.e. a file in the directory) is met.  

Quicker and not that much dirtier is a shell script something along the lines of this:

-----------------------[ snip ]---------------------
#!/bin/bash

directory_to_watch=/path/to/some/directory
cd $directory_to_watch

for file in $(ls); do
   # do something to each $file here
done

-----------------------[ snip ]---------------------

schedule this to run every couple of minutes and voila, a folder watcher.

--Philip

On Wed, Feb 20, 2002 at 12:31:34PM -0800, Sam Hunting wrote:
> At least I think it's the shell.
> 
> What I want to do is create a "magic" directory, such that when a
> document gets put into it, that document is processed in a certain way
> by an application.
> 
> It sounds to me like what I want is a "listener" that lives in the
> background, detects when a "new" file (or alias to a file) is added to
> the directory, sends the file (or aliased file) off to the processor,
> and then marks the file or alias in such a way that it is no longer
> percieved as new.
> 
> Is there a name for what I want to do, and can someone point me to some
> sample code that shows how to do it? (The kind of code where, since I
> am a newbie, there's little danger of erasing my hard disk or some
> such...)
> 
> Many thanks!
> 
> S.
> 
> 
> =====
> <!-- Topic map consulting:          www.etopicality.com 
>      Open source topic map toolkit: www.goose-works.org 
> 
> "A human is a topic map's way of making another topic map."
> 
> -->
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - Coverage of the 2002 Olympic Games
> http://sports.yahoo.com
> 
> ______________________________________________________________________
> Philadelphia Linux Users Group       -      http://www.phillylinux.org
> Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
> General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug
> 

______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug