Is there any way to have a script run (either on a web page or a shell script) when new files are put in a folder. E.g we have order response notification XML files uploaded to our server. They are uploaded via sftp. What i wondered if there was some way to monitor the contents and if new files with the correct extesions are uploaded then a script would run to process them.
Or maybe i should just use a daily cron if all else fails?
if [ -f "$file_name" ]; then
echo "file exists"
ls -l "$file_name" | grep "permissions" 2>/dev/null
if [ $? -eq 0 ]; then
echo "proper file present"
## proceed with the steps needed
fi
fi
First start off by creating the .toc file toc=table of contents
ls -tl <your directory> > <your directory>/.toc
Next create a script that does the following:
ls -tl <your directory> > /tmp/.toc # or what ever dir you want just make
# sure your not overwriting
# the current .toc file.
diff /tmp/.toc <directory with orig>/.toc > /dev/null 2>&1
if [$? -ne 0 ]
then # something changed
mv /tmp/.toc <directory with orig>/.toc
Do the rest of your processing
....
.....
.....
.toc
else
echo "No changes"
fi
Note: I prefernce .toc with the "." so a simple ls command will not pick
it up. You can run this as often as you like.