[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Question about app or script to monitor changes

Posted on 2006-06-03
Medium Priority
Last Modified: 2010-04-21
I wrote a bash script that reads a file, does a bunch of stuff then writes a value into mysql.
We then made this script loop and have it load on startup in a cron job.

Is there a better way to do this?  Basically I have a dir, where the files are being constantly updated - and what I would like to know is when the file changes. Then write to db.  Is there a better way to program this?  Any recommendations?  

Right now, I just keep reading the file, and if its different than what I have in my db, I write to log and update current value.

Looking for suggestions.  Just as a side note -- we had a vb.net app that would load current value into a text box, then when the text box would change -- to do what it needed to do.  Looking to do something compareable in Linux.  We do have it working with bash and mysql right now... seeing if there is a better way.

Question by:Tigger996
LVL 35

Accepted Solution

Duncan Roe earned 672 total points
ID: 16826729
I'm not aware of any way a process can be notified that the content of a file has changed. All methods I can think of require some kind of polling. You could poll the file's date-time-modified (DTM). AFAIK, that's updated whenever the file is written to. Or you could md5sum the file, and only re-process it when the sum changes. That's a much lower processing cost than reading and processing with bash, so you could afford to do it more often. Any shell pipeline I can think of right now to even extract DTM would cost more than the md5sum, unless the file is large.
LVL 43

Assisted Solution

ravenpl earned 664 total points
ID: 16827793

Assisted Solution

devrick0 earned 664 total points
ID: 16828096
What is writing to the files in the directory that is constantly being updated?  You could throw a wrapper on that program/process to have it make the change to the database for you, or even back up the file in another directory and save the last x number of changes.  I do something similar with vim.  Everytime I open a file to editing with vim, vim gets called through a function in my bash profile that creates a backup and stores the last 10 changes for me.  Just a thought.  

LVL 43

Expert Comment

ID: 17379488
The only reasonable and safe and fase (supported by the kernel) is the gamin(FAM does polling). It should not be split...
LVL 20

Expert Comment

ID: 17379952
The three comments are giving good information.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question