Backwards

Modify folder structure

Mini-guide - 03/01/2017

An example script to notify the change, the removal or the addition of a file in a specific folder.


Inotify is requested.

BASH script


#!/bin/bash
token="TOKEN"
testonoti="File is changed in the Folder"

folder="/home/gab/dir"


while inotifywait -qqre modify "$folder"; do
    curl --request GET "https://api.rpinotify.it/notification/$token/text/$(echo ${testonoti// /%20})"
done
						

It works in a very simple way. Every time a folder changes, the script sends a notification
To detect the changeInotify was used.

The variables of the script:

  • $tokenPersonal token assigned during the registration process.
  • $testonotiNotification text.
  • $folderPosition of the folder to monitor.

The call structure HTTP GET is very simple.

https://api.rpinotify.it/notification/$token/text/$testonoti

Variable name Description Format
$token Personal token. Alphanumeric string
$testonoti Text notification. Text without spaces (use %20)

Execute the script on startup

You can execute the script on startup so that the folder is ALWAYS monitored.

You can use cron, a very popular tool used to plan operations on linux systems.

To execute the script on startup insert the line @reboot sh fineinfolder.sh in crontab.



Dove fileinfolder.sh is the position of the script in the device.

For the execution of the script authorizations are necessary. Authorizations can be given by entering chmod 755 diskquota.sh

RpiNotify is an Italian project supported by RaspberryItaly

The first Italian RaspberryPi community.