INCRON Event Script/Command Not Running

99 Views Asked by At

I upload a file from a bike computer to my PC via Dropbox (bike computer->Dropbox->my PC) and want to start a Python program when this happens. Today, I have a CRON entry that runs every 5 minutes looking for a file but I want this process to be triggered when the file is uploaded.

I have installed INCRON and defined an event table to test that this will work when a file is uploaded. The event table for this test (and for my experience):

/home/dave/Dropbox/Test/        IN_CLOSE_WRITE  /home/dave/Scripts/TestFileFound.sh $#

All I am trying to do here is trigger the 'TestFileFound.sh' script when a file is created in the specified folder and pass the file name to the script ($#).

I can see that the event is triggered when I create a new file in the folder:

Feb 02 15:27:16 davesdesktop incrond[561422]: PATH (/home/dave/Dropbox/Test/) FILE (TestFileFound.txt) EVENT (IN_CLOSE_WRITE)
Feb 02 15:27:16 davesdesktop incrond[561422]: (dave) CMD (/home/dave/Scripts/TestFileFound.sh TestFileFound.txt)

INCRON says the script is started but it does not execute. If I run the script from the command line, it works as expected, producing the file in /tmp and sending the email. The script:

#!/bin/bash
set -eu
# Original:   V1
echo "From TestFileFound.sh: Test File '$1' from '$HOME/Dropbox/Test' was found!!!!" > /tmp/TestFileFound_Message.txt 
# Send email 
EMAIL="<my email address>"  (Redacted)
SUBJ="Test File from '$HOME/Dropbox/Test' was found!!!!"
mail -s "$SUBJ" "$EMAIL" < /tmp/TestFileFound.txt

exit

It is marked executable:

[15:20:30 ~]$ ls -l Scripts/Test*.sh
-rwxrwxr-x 1 dave dave 312 Feb  2 15:22 Scripts/TestFileFound.sh

I do not see the file created by the 'echo' message in the /tmp folder nor do I see any emails when this script is triggered by the INCRON event.

I have various scripts and Python programs scheduled by my user CRON that successfully create emails to notify me when they have completed and I see those emails in my GMAIL inbox.

What have I not done or done incorrectly that this script is not running when triggered by INCRON?

Thanks ahead of time for any solutions or suggestions you can offer.

1

There are 1 best solutions below

0
On

I have found that INCRON is working as intended but has a flaw that anything triggered by it can't access the system-wide '/tmp' directory (I do not know why since the same scripts triggered by my personal 'cron' work fine with write access to '/tmp'.)

The work around is simple - create a 'tmp' under your home folder and modify the scripts & programs triggered by INCRON to use this folder.