1

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

user1403333
  • 98
  • 12
  • Given the resolution, the claim that the script was never executed was inaccurate. – Charles Duffy Dec 15 '15 at 15:41
  • no, actually it was not executed because of the >> /var/log etc. thing, I am not completely sure about that, but I think it only executes /usr/python3 although showing everything as CMD in the syslog, I will evaluate this further, when I have some free time. – user1403333 Dec 15 '15 at 15:47
  • Probably that means that incron isn't using `system()` -- and going through a shell -- but is instead executing contents with `execve()`. If it obeys regular shell-parsing rules (which I'm not willing to place bets on in either direction), you could run `sh -c '/srv/parser "$@" >>/path/to/log' _ $@/$#`, thus putting the redirection into the text passed to the shell with `sh -c` but keeping the directives for extra arguments to be interpreted by incron outside. (The `_` is a placeholder for `$0`, such that the value used for `$@/$#` will become `$1`, as long as it's passed as a single word). – Charles Duffy Dec 15 '15 at 18:02
  • I looked up the source code and It seems you are right: in line 387 of usertable.cpp we find: if (execvp(argv[0], argv) != 0) ... – user1403333 Dec 15 '15 at 18:49
  • 1
    I just saw they fixed this in 0.5.11 by writing: execlp("/bin/bash","/bin/bash", "-c", cmd.c_str(), (char *)NULL); but my jessy still uses 5.10 – user1403333 Dec 15 '15 at 18:58
  • I had big trouble running multiple commands in the same command line, so I ended up putting everything into a bash script and then execute that from the incron file instead. – TheStoryCoder Dec 12 '18 at 13:44

1 Answers1

0

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 $@/$#
user1403333
  • 98
  • 12
  • I've same error and had try your solution but didn't work for me. `/ftp/ftp1/dbg/10.10.252.121 IN_CLOSE_WRITE python2.6 /ftp/ftp1/dbg/lpr_10.10.252.121.py 10.10.252.121` – Yohanim Jun 06 '18 at 03:46