Score:1

Incron Not Starting Script

in flag

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/apps/WahooFitness/   IN_CLOSE_WRITE   /bin/bash /home/dave/Scripts/WahooFileFound.sh $#
/home/dave/Dropbox/Test/        IN_CLOSE_WRITE   /bin/bash /home/dave/Scripts/TestFileFound.sh $#

The first line of the 'incrontab' is for a file to be uploaded from my bike computer. The second is simply a test since I ride only once a day. Once I am confident this test will work, I will schedule a Python program to run when the real bike computer file is uploaded.

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>" 
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.

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.

Dave

uz flag
Jos
You could look into `inotifywait` (https://manpages.ubuntu.com/manpages/bionic/man1/inotifywait.1.html)
Freddy avatar
cf flag
You're writing to `/tmp/TestFileFound_Message.txt` and then you're reading from `/tmp/TestFileFound.txt` while it would be easier to just do `echo "..." | mail -s subject email`, but that's a another issue. You can also remove `/bin/bash` from the table since the script is executable. Do you see anything in your logs?
hr flag
I wonder if `$HOME` is unset in the incron environment, and that is causing your `set -eu` to exit the script? Perhaps try commenting that out for testing purposes.
Dave Nagy avatar
in flag
The TestFileFound_Message.txt was simply to see if the script was working and the email was not working. When I get this to work, it will execute a Python program. I tried it with and without the 'bin/bash' prefix to the command with identical results. Logs show exactly what the status messages show - INCROND executed a CMD of the script I set. Thanks for suggesting!
Dave Nagy avatar
in flag
Thanks for the tip for inotifywait. I'll see if this will work.
Dave Nagy avatar
in flag
I have learned a lot about INCRON, mostly from: https://hackaday.com/2020/10/28/linux-fu-troubleshooting-incron/ and have been successful with my tests to determine if I can rely on it to react when a new file is uploaded from my bike computer. I've learned that INCRON doesn't like it if I use the /tmp folder (per the referenced web site) so I changed all of this to $HOME/tmp. I have also learned that the Dropbox daemon doesn't seem to open & close a file when it is moved from the cloud to my local Dropbox folder but that an event IN_MOVED_TO will catch this.
Score:0
in flag

More is available at https://hackaday.com/2020/10/28/linux-fu-troubleshooting-incron/

  1. Use $HOME/tmp for temporary files in scripts started by INCRON.
  2. Determine what events will happen when a monitored directory/folder have new files loaded into it. Dropbox doesn't trigger the WRITE or CLOSE events (any of them) when moving a file from the cloud to your local Dropbox folder.
  3. The referenced site on the first line of this answer has sample scripts to help determine what events are happening.

Thanks for all of the suggestions!

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.