Tech Support > Operating Systems > Linux / Variants > MONITOR/WATCH DIRECTORY AND PROCESS??
MONITOR/WATCH DIRECTORY AND PROCESS??
Posted by AB PP on March 6th, 2004


What would be an efficient and proper way to implement a shell script
to monitor/watch a directory and process/move/copy files added to
it?? I made one having a "while (1)" loop but that takes a lot of
CPU power! Any other idea??

Posted by Dances With Crows on March 6th, 2004


On Sat, 06 Mar 2004 18:22:46 -0500, AB PP staggered into the Black Sun
and said:
You can use fam to do this (man 3x fam) but that would require writing a
C program. There's always the option of polling the directory for
changes every N seconds instead of polling it continuously; use sleep
kind of like so:

while true ; do
POLL_DIRECTORY_FOR_CHANGES
sleep 5
done

....adjust the sleep interval to taste. If you need subsecond resolution
on the polling, I think you're going to have to write something other
than a shell script. HTH,

--
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
Brainbench MVP for Linux Admin / mail: TRAP + SPAN don't belong
http://www.brainbench.com / Hire me!
-----------------------------/ http://crow202.dyndns.org/~mhgraham/resume


Similar Posts