Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to watch for any input given to or any changes that made in the present content over a file, upon any modification i need to run a python program which is located in the same folder.

I tried my best to understand but i'm not able to get any good result. It would be of great help, if anyone can help me through this.

share|improve this question
add comment

1 Answer

You can do one of two things.

  • You can write a program that directly hooks into the inotify API and reacts to change events. This is probably the most elegant, but way outside the scope of ServerFault.
  • You can use inotifywait (part of inotify-tools) to monitor a file and fire off a script whenever something happens.

For inotifywait, you'd want to set up a shell script (in init.d, most likely) to do something along these lines:

#!/bin/sh
while inotifywait -e modify /path/to/file
do
   /path/to/reaction_script.py
done

DON'T use the -m switch when you're calling inotifywait in a conditional like this; It will not work.

share|improve this answer
    
i was actually using pyinotify, but here i couldn't find the tag since i'm new not given the right fir creating the tag even, anyways i found out the solution using the event handler in pyinotify. Thanks a lot for your time :) :) –  Bhuvan raj May 13 '11 at 20:27
    
No problem. As I said, though, most anything beyond basic bash/vb scripting is usually outside the scope of ServerFault. You may be better (more quickly/accurately) served on Python questions at our sister site StackOverflow.com –  Hyppy May 13 '11 at 20:37
    
But sorry i cannot accept your answer since i haven't tried it out.:-/ Have a good day :) :) –  Bhuvan raj May 13 '11 at 20:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.