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

incron "runs" once and then it won't "watch" again #12

Open
MaxBenn opened this issue Feb 8, 2020 · 7 comments
Open

incron "runs" once and then it won't "watch" again #12

MaxBenn opened this issue Feb 8, 2020 · 7 comments
Labels

Comments

@MaxBenn
Copy link

MaxBenn commented Feb 8, 2020

What have i done so far?
I set up my table as followed: incrontab -e
/folder/.hiddenfolder/file IN_ATTRIB cp /folder/.hiddenfolder/file /folder/.hiddenbackup/$$(date +%Y%m%d)_file

After Accessing my file and saving the changes I do get my backup file.
On ls -l /folder/.hiddenbackup/ id shows me my file named: 20200208_file

Here comes the tricky part:
Now I access my file again, make some changes and save it but nothing happens.

when I check service incron status it showes me, that the service is running and active but no further event happened.

Anyclue why and what is going on?
I have tried IN_ATTRIB,IN_ONESHOT ... I've even tried IN_ALL_EVENTS.
When I use IN_ATTRIB only then i get a line in service incron status that says:
Feb 08 08:48:20 example.com incrond[1116]: PATH (/folder/.hiddenfolder/file) FILE () EVENT (IN_IGNORED)

After service incron restart everything works... but only once.

Thanks & Cheers,
MaxBenn

@wiktor2200
Copy link
Contributor

wiktor2200 commented Feb 8, 2020

Hi there I've encountered such a problem some time ago. And I find somewhere info that running nested commands is disabled in incrontab for security reasons. But I developed workaround solution.
Here it it ;)

  1. Watch whole directory rather than file
    Watching files can causes problems when you have for example noatime parameter in fstab
  2. Run bash script in incrontab rather than complex commands.
  3. Log triggers in logfile it's easy when using script.

Example which shows solutions for your problem.

Incrontab entry (you can place bash script wherever you want)

/folder/.hiddenfolder IN_CLOSE_WRITE bash /folder/backup.bash $@ $#

Bash script

You can set your variables and set all needed conditions when it comes to filename which is tracked.

#!/bin/bash

LOGFILE_PATH="/folder/log.txt"
BACKUP_DIR="/folder/.hiddenbackup/"

# Check if deleted file's name is "file"
if [ "$2" == "file" ]; then

  # Copy $1 - aims to path, $2 - to filename - it corresponds with $@ $# incron parameters
  cp "$1/$2" "$BACKUP_DIR/`date +%Y%m%d`_file"

  # Simple logging
  echo "`date +%F_%T` $1/$2 is copied to backup directory" >> "$LOGFILE_PATH"
  exit;

else
  exit;
fi

I hope it will help you.

@wiktor2200
Copy link
Contributor

And when it comes to this bug it's caused by triggering IN_IGNORED status after running once.
I think removing/commenting line:
https://github.com/ar-/incron/blob/1eedfbc9b318372efd119fd17f4abdbde561a53d/inotify-cxx.cpp#L458
could help, but it needs more testing.

@MaxBenn
Copy link
Author

MaxBenn commented Feb 8, 2020

@wiktor2200 Thank you a lot for your effort...
I just copied your script and tested it.
After I was done testing I made some minor changes like date +%Y%m%d_%H%M%S_file an so on but it works flawlessly.

+rep to you! :D

Thanks & Cheers,
MaxBenn

@MR-Diamond
Copy link

Same issue here: I'm watching a file for modifications (eg by using IN_MODIFY) but it works only once, then I always get PATH (/path/to/file/to/watch) FILE () EVENT (IN_IGNORED) and the action isn't triggered anymore by incrond (I should run systemctl status incrond.service but is not a solution).

I also tried IN_CLOSE_WRITE and IN_ATTRIB but unsuccesfully; I didn't find any workaround.

@MR-Diamond
Copy link

I think removing/commenting line:
https://github.com/ar-/incron/blob/1eedfbc9b318372efd119fd17f4abdbde561a53d/inotify-cxx.cpp#L458
could help, but it needs more testing

I recompiled incron by removing this and any other references about IN_IGNORED, but the mentioned issue, still persists.

@danfruehauf danfruehauf added the bug label Sep 6, 2021
@nre-ableton
Copy link

I've just run into this issue myself. The key workaround is mentioned by @wiktor2200 here:

Watch whole directory rather than file

So it seems that incron has some issues correctly watching single files. Unfortunately for me, I'm unable to watch the file's parent directory, since it's a directory that will receive a huge number of events and I only want to be notified when a particular file in this directory that seldom changes is changed.

This bug is quite old, is there any timeline on when it might be fixed?

@x4IPx
Copy link

x4IPx commented Sep 26, 2023

Good afternoon. I also see this bug.
root

/home/fly/test/testfile IN_ALL_EVENTS   echo "$$ $@ $# $% $&

When I edit a file via nano there are no problems.
When I edit through neovim, I get the IN_IGNOREDand tracking stops working.

**Sep 26 16:44:23 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_OPEN)
Sep 26 16:44:23 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_OPEN 32)
Sep 26 16:44:23 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_CLOSE_NOWRITE)
Sep 26 16:44:23 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_CLOSE_NOWRITE 16)
Sep 26 16:44:23 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_OPEN)
Sep 26 16:44:23 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_OPEN 32)
Sep 26 16:44:23 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_ACCESS)
Sep 26 16:44:23 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_ACCESS 1)
Sep 26 16:44:23 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_CLOSE_NOWRITE)
Sep 26 16:44:23 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_CLOSE_NOWRITE 16)
Sep 26 16:44:34 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_ATTRIB)
Sep 26 16:44:34 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_ATTRIB 4)
Sep 26 16:44:34 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_DELETE_SELF)
Sep 26 16:44:34 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_DELETE_SELF 1024)
Sep 26 16:44:34 u1-g6 incrond[1418]: PATH (/home/fly/test/testfile) FILE () EVENT (IN_IGNORED)
Sep 26 16:44:34 u1-g6 incrond[1418]: (root) CMD (echo "$ /home/fly/test/testfile  IN_IGNORED 32768)**

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

No branches or pull requests

6 participants