Running python script in incrontab in Debian

Posted by WilliamMayor on Server Fault See other posts from Server Fault or by WilliamMayor
Published on 2013-11-09T11:06:06Z Indexed on 2013/11/09 15:57 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

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 /var/log/syslog:

$ touch /home/dropbox/test/a
$ tail /var/log/syslog
...
Nov  9 10:18:27 vps incrond[1354]: (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[1354]: (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 .../monitor.py to /usr/bin/python2.7 .../monitor.py just in case but it didn't make any difference.

© Server Fault or respective owner

Related posts about debian

Related posts about python