Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to monitor directory for new files only.

Status
Not open for further replies.

nuch

Technical User
Feb 4, 2003
1
US
This directory already has files in it. My script - if new file exists it processes it and directs the output to another directory, sleeps for 10 seconds, then check for new files, if none, sleeps again.

Is there a way to script it without using "sleep"? Triggers the script when new files arrive.

Thank You
 
An alternative to sleep or cron is the at command. However, I'm ignorant of the use, sorry. But using sleep, this might work, or at least get you started. I'm not at a unix/linux workstation right now so I can't test it but...


while true
do
fileCount1=`ls -la | wc -l`
sleep 1200
fileCount2=`ls -la | wc -l`
if test $fileCount2 = $fileCount1
then
echo "" > /dev/null
else
ls -la | mail -s "Added Files!!" userID
fi

done

 
Maybe whoever sends those files can setup a trigger. What is the concern with 'sleep' command? If seconds counts in your process, you may set a loop forever. If it is not that urgent, most books would suggest a sleep command. Sleep time does not comsume CPU, the way I learned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top