I have installed and configured incron on Ubuntu server 16.04. Now I want to monitor if files are added to a specific folder. This works well because when I have
incrontab -l
/var/www/html/uploads IN_ATTRIB touch /home/incronuser/test.txt
and when a file gets added to the uploads folder, the test.txt file gets created in the users home.
Also, if I echo something instead of doing the touch, in both cases I see the incron
activity in /var/log/syslog
. So that all works as expected.
But now I want to run a bash script when a file is added to the uploads folder. This script works well when the same user that created the incron job does:
~$ bash /home/incronuser/myscript.sh
It runs fine and the script does what it is supposed to do.
Now I change my incron job to run that script when triggered:
incrontab -e
/var/www/html/uploads IN_ATTRIB /home/incronuser/myscript.sh
But I cannot get this to work for the life of me.
Following other Q&A on here and elsewhere on the internet, I have tried using quotes in various forms, tried using the bash command in the crontab
line but all have failed up to now. Things like:
/var/www/html/uploads IN_ATTRIB bash /home/incronuser/myscript.sh
/var/www/html/uploads IN_ATTRIB /bin/bash /home/incronuser/myscript.sh
"/var/www/html/uploads IN_ATTRIB /home/incronuser/myscript.sh"
/var/www/html/uploads IN_ATTRIB "/home/incronuser/myscript.sh"
/var/www/html/uploads IN_ATTRIB sudo bash -c "/home/incronuser/myscript.sh"
I have to add that in all these cases, I do see the incron
job being called in syslog
, just nothing happens. I am not really sure where I could find more detailed logs of what is going wrong. Would be great to get some insight on this.
$PATH
contains/usr/bin:/bin
, so if your script uses commands that are located outside of these directories you should call these commands by using the full path to their locations. – pa4080 Feb 24 '18 at 8:33