From 6d02ca0e2ab8dc81c69aa3fc5fe245ebc5de6b31 Mon Sep 17 00:00:00 2001 From: m0wer Date: Sun, 7 Apr 2024 08:53:01 +0200 Subject: [PATCH] add notifications instructions --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index fcfb5bb..008c526 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,34 @@ cp .env.example .env # edit the .env file docker compose up -d --build ``` + +## Notifications for sigunps + +Here is an example script that uses `telegram-send` to send a notification +every time someone signs up: + +```bash +#!/bin/bash + +DIRECTORY_TO_WATCH="/data/idea/data/" + +# Check if DIRECTORY_TO_WATCH was provided +if [[ ! -d "$DIRECTORY_TO_WATCH" ]]; then + echo "Error: Directory '$DIRECTORY_TO_WATCH' does not exist." + exit 1 +fi + +# Using inotifywait to monitor for 'create' and 'modify' events on CSV files +inotifywait -m -e create -e modify -e moved_to --format '%w%f' -q "$DIRECTORY_TO_WATCH" | while read FILE_PATH +do + # Check if the event pertains to a CSV file + if [[ $FILE_PATH == *.csv ]] + then + # Get the last line from the file + LAST_LINE=$(tail -n 1 "$FILE_PATH") + + # Send the last line via telegram-send + telegram-send "$(basename $FILE_PATH): $LAST_LINE" + fi +done +```