pythonincron

incrond doesn't execute python script


I need to run a python script on every file, that is written into a specific folder. So I created a file in /etc/incron.d/ and added the following line:

/srv/ftp IN_CREATE /usr/bin/python3 /srv/parser.py $@/$# >> /var/log/parser/incron.log 2>&1

the syslog shows me:

incrond[32630]: (system::parser) CMD (/usr/bin/python3 /srv/parser.py /srv/ftp/00008260_2015-12-09T17-31-36.csv >> /var/log/parser/incron.log 2>&1)

but the log is empty, and the script did not do anything


Solution

  • I found the problem: IN_CREATE fires even if the file is not completely written, because of this, it works on when copying is extremely fast, like cp a 10kb file from one folder to another, but definitely not over FTP, the correct event is IN_CLOSE_WRITE, it will fire after the ftp server does a fclose(), and secondly inconrd does not like more than one command

    so the following works:

    /srv/ftp IN_CLOSE_WRITE /srv/parser.py $@/$#