I've installed a python package which tracks file changes called when-changed (https://github.com/joh/when-changed). Now the command I want to run is:

when-changed /var/www/html/php/logfile.csv /var/www/html/php/processpayment.sh

When I modify the logfile.csv the code in processpayment.sh gets executed. However, when I put this command in my /etc/rc.local file and reboot the system the script won't execute when I modify the file! I have 3 assumptions:

  1. The when-changed tool is crap,it doesn't work as a daemon.
  2. /etc/rc.local is not the place to put this daemon (I've tried putting it in /etc/init/whenchanged.conf to no avail)
  3. the daemon needs to be attached to pts/O and not in ?

For reference, the bottom process works:

root      1331  0.5  0.4 275480 17376 ?        Sl   16:14   0:04 /usr/bin/python /usr/local/bin/when-changed /var/www/html/php/logfile.csv /var/www/html/php/processpayment.sh
root      3547  7.0  0.4 267024 16868 pts/1    Sl   16:27   0:00 /usr/bin/python /usr/local/bin/when-changed /var/www/html/php/logfile.csv /var/www/html/php/processpayment.sh

The script:

# called when logfile.csv changes
# scrapes logfile.csv and runs the mintscript
IN=$(cat logfile.csv | tail -n1 | cut -d';' -f4,6 | xargs)
arrIN=(${IN//;/ })
node "soupcoinmintscript.js" $address $amount | tee "log"
exit 0;

The startup config:

/etc/init# cat whenchanged.conf 
start on startup
when-changed /var/www/html/php/logfile.csv 
  • 1
    What specific distro are you using? Some distributions have deprecated init.d in favor of systemd. Also it's not that nice to say that when-changed is crap. The developer made it with a certain set of requirements, and he's willing to share it with you (for absolutely free). If you feel it doesn't suit your needs, change the code and submit a pull request to him. If you don't want to do that, write your own code. – mtak Jul 12 '17 at 17:55
  • @mtak you're absolutely right, I was just a tad bit frustrated ; - ). I believe it is ubuntu but I'll report more specifically soon. – wimdetr Jul 12 '17 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.