Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop when invoke "ls -la" in watched directory #8

Open
jlegido opened this issue May 9, 2015 · 1 comment
Open

Infinite loop when invoke "ls -la" in watched directory #8

jlegido opened this issue May 9, 2015 · 1 comment

Comments

@jlegido
Copy link

jlegido commented May 9, 2015

Not sure if it's a bug or not, but just in case let me provide details:

  1. Get watcher (I downloaded it 09/05/2015)
cd /tmp; git clone https://github.com/splitbrain/Watcher
  1. Create below .ini file:
sudo vim /etc/watcher.ini
[DEFAULT]
logfile=/tmp/watcher.log
pidfile=/tmp/watcher.pid
[job1]
; directory or file to watch.  Probably should be abs path.
watch=/tmp/test
events=close
excluded=
recursive=true
autoadd=true
command=ls -l $filename
  1. Create watched dir:
mkdir /tmp/test
  1. Start the daemon and tail life the logs:
cd /tmp/Watcher; ./watcher.py start
tail -F /tmp/watcher.log
  1. Go to the watcher directory and issue a "ls -la" command:
cd /tmp/test; ls -la

Expected behaviour The log shows nothing, since no file was closed (maybe I'm wrong in this assumption...)
Found behaviour The daemon starts writing the log without stopping:

Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
Close nowrite:  /tmp/test
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
total 0
@bertalanimre
Copy link

I personally think you install watcher the wrong way. Why do you create a separate ini file on the first place? Here is how I use watcher:

  • Install python 2.7 and inotify
  • Clone watcher to opt folder
  • Sofl-link the included ini file to /etc
  • Soft-link the included wathcer.py to /bin as watcher
  • Create a proper log folder in var
  • Edit the ini file according to my needs
  • Starting watcher
  • Checking if it works fine
sudo yum install python python-inotify
sudo git clone https://github.com/splitbrain/Watcher.git /opt/watcher
sudo ln -s /opt/watcher/watcher.ini /etc/watcher.ini
sudo ln -s /opt/watcher/watcher.py /bin/watcher
sudo mkdir /var/log/watcher
sudo vim /etc/watcher.ini
sudo watcher start
sudo tail -f /var/log/watcher.log

Also, if you use multiple bash command, I suggest using && (and-and) instead of ; (semicolon). This way, if one of the commands fails, the remaining commands won't try to run and ruin the system possibly. Or if you want to have a more complex command list, use a bash script and run that with watcher.

My thoughts about your command is that you specified "close" operation to be executed and made the command recursive. Close means any operation that accesses a file and then leaves it. So you basically told watcher to watch the whole test folder in your tmp folder and whenever an application accesses a file and then closes it, the command should be executed. I don't know what is your exact project, but maybe you wish to have a create,modify instead of close as events watched for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants