Running python script in incrontab in Debian

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/
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/ | logger
/home/dropbox/test IN_CREATE logger "$$ [email protected] $# $% $&"

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/ | 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 .../ to /usr/bin/python2.7 .../ 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/

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
logger "$PATH"
/usr/bin/python2.7 /home/dropbox/ | logger

This produces the following output:

$ tail /var/log/syslog
Nov  9 23:50:28 vps incrond[1354]: (dropbox) CMD (/home/dropbox/
Nov  9 23:50:28 vps logger: /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin

So nothing from 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.

Server Fault Asked by WilliamMayor on November 14, 2021

2 Answers

2 Answers

I feel like an idiot for noticing this one.

My script attempts to get a file lock before it starts messing around with dropbox stuff. This is mostly to stop other instances of from interfering. The path to the file I lock wasn't absolute.

So, lesson to anybody that finds this page in the future. Check every path that you use to make sure that it's either 1) on the path 2) absolute.

Answered by WilliamMayor on November 14, 2021

There's a big difference between cron and incron: the way they execute the commands. Cron sees the command as one argument and calls a shell to run it. Roughly like this:

execvp('/bin/sh', ['/bin/sh', '-c', 'whatever is in the crontab']);

So all shell constructs like && and | work. Incron does not do this, it parses the command itself and execs it directly. So what incron runs in your case is:

execvp('/home/dropbox/', ['/home/dropbox/', '|', 'logger']);

So your gets run with | and logger as arguments. You can either wrap your script in another script that does | logger or use the python logging module to do the logging from itself.

Answered by Dennis Kaarsemaker on November 14, 2021

Add your own answers!

Related Questions

Asterisk / Elastix Address Book and Call Recording

1  Asked on December 3, 2020 by ullash


How to know if mysql server is using sha_256 or caching_sha_256?

0  Asked on December 2, 2020 by noah-j-standerson


Booting a squashed filesystem from ISO

0  Asked on December 2, 2020 by rudolfs-bundulis


DC for new Hyper-V cluster

3  Asked on December 1, 2020 by counter-hulak


With Glassfish, how to resolve https URL to http URL

1  Asked on November 29, 2020 by tale852150


Apache PHP-FPM “Software caused connection abort”

1  Asked on November 29, 2020 by craig-francis


NGINX Enable CORS for a Google Places API call

1  Asked on November 29, 2020 by eusthace


Ask a Question

Get help from others!

© 2021 All rights reserved.