1

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.

1 Answer 1

2

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.

3
  • 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, 2011 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, 2011 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, 2011 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .