I have a user, dropbox, that runs the Dropbox daemon, I want to monitor the directories in the Dropbox directory for new files and run a python script when they appear.
I have the python script that I know works:
$ /home/dropbox/monitor.py Trying to get lock Got lock, waiting for Dropbox to be idle Dropbox idle Finding instructions Done, releasing lock
I have an incrontab entry:
$ incrontab -l /home/dropbox/Dropbox IN_CREATE /home/dropbox/monitor.py | logger /home/dropbox/test IN_CREATE logger "$$ $@ $# $% $&"
When I add a file to the test directory I see the output in
$ touch /home/dropbox/test/a $ tail /var/log/syslog ... Nov 9 10:18:27 vps incrond: (dropbox) CMD (logger "$ /home/dropbox/test a IN_CREATE 256") Nov 9 10:18:27 vps logger: "$ /home/dropbox/test a IN_CREATE 256" ...
However, when I add a file to the Dropbox directory the command doesn't seem to run:
$ touch /home/dropbox/Dropbox/a $ tail /var/log/syslog ... Nov 9 10:24:16 vps incrond: (dropbox) CMD (/home/dropbox/monitor.py | logger) ...
So the incron daemon notices the new file and the correct command is found to be executed but it never actually gets executed. Nor are there any error messages. It kind of seems like incrontab can only be used to run the most simple of commands.
This might be a similar question to:
but I think that I don't have env problems, every path is absolute. I tried changing
/usr/bin/python2.7 .../monitor.py just in case but it didn't make any difference.
Dennis Kaarsemaker offered a solution that incrontab was executing my command in a non-cron manner and that this might be causing the problem. Unfortunately, I still can't get it to work.
First I removed the extra stuff from the incrontab:
$ incrontab -l /home/dropbox/Dropbox IN_CREATE /home/dropbox/monitor.py
This should run just my monitor file and not try to pass anything in as arguments. No dice, still no output.
Then I created a bash script that contained the execution instruction for my script:
$ vim test.sh logger "$PATH" /usr/bin/python2.7 /home/dropbox/monitor.py | logger
This produces the following output:
$ tail /var/log/syslog Nov 9 23:50:28 vps incrond: (dropbox) CMD (/home/dropbox/test.sh) Nov 9 23:50:28 vps logger: /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin
So nothing from monitor.py and we can see that the directory containing python is in incrontab's environment, so we shouldn't even need to specify the path as absolutely as we do.