How to run a bash/perl script that gets triggered when a file has been received in a directory
Posted on 2011-09-04
I have a requirement wherein a third party machine will be SCP-ing a log file into a user directory on my mySQL server. I need a mechanism wherein if the file "arrives" it would kick off a script that would process the log file and eventually upload it to my MySQL database.
While google searching, I keep stumbling on "inotify" and "fschange". In my case, it looks like inotify is simpler to implement,...although for my very simple requirement, even a regularly firing (1 minute interval) cron job will do.
The problem with the inotify google searches i stumble into is that they just keep referencing the same inotify syntax and no one actually gives a real world example of how to use it.
In my application, the received file could be quite large and could take up to a minute to transfer over, so I need a script that actually checks to see if the file stops growing....and then...start parsing it.
Any suggestions on how I can implement this would be much appreciated.
Thanks very much.