Δευτέρα 9 Μαρτίου 2015

Using IFTTT recipe to run a shell script

Requirements:

-an IFTTT account
-a Dropbpx account linked to your IFTTT account
-a server running linux (mine runs Debian linux).
- incrontab package, available on most linux distros.

First of all, install Dropbox on your linux box. You may find instructions here:
https://www.dropbox.com/install?os=lnx
Run Dropbox and create a folder named IFTTT on your home Dropbox folder.

mkdir ~/Dropbox/IFTTT

Then, you have to create your IFTTT recipe at ifttt.com. You may use whatever "this" statement you wish. On "that" statement you chose Dropbox, and create a file. Give a name to your file, for my example I use "runme". In the content you may put whatever you want. In Dropbox folder path you use IFTTT.

Create your script file on your home folder named "script.sh" and make it executable: chmod +x script.sh. Make sure your script executes properly:

./script.sh

Add the user that has both rights to run the script and to write into the Dropbox folder in the incrontab allow list:

echo bob >/etc/incron.allow

Then modify your incrontab. This package continuously checks a folder for changes. In my example it will check my IFTTT folder for modifications.

incrontab -e

inside your incrontab file paste:

/home/bob/Dropbox/IFTTT/ IN_MODIFY,IN_CREATE,IN_MOVED_TO /home/bob/script.sh

Checking that incrond is working:

Open a new terminal window and run:
sudo tail -f /var/log/syslog | grep incrond

Then, create a file inside your /home/bob/Dropbox/IFTTT folder:

touch /home/bob/Dropbox/IFTTT/lala

You will instantly see on your logs:

Mar  9 15:50:03 linuxbox2 incrond[361]: (bob) CMD (/home/bob/script.sh)

This means that your script just triggered and will trigger every time your recipe runs!

1 σχόλιο: