Strumenti Utente

Strumenti Sito


linux:openmediavault:avviso_ad_ogni_login

Avviso ad ogni login

Creare uno script che esegua l'avviso vero e proprio.
Ad esempio, creare il seguente file per inviare un avviso tramite telegram:

send_generic_telegram_notification
#!/bin/bash
#Version 2
TOKEN="YOUR_TOKEN"
CHAT_ID="YOUR_CHAT_ID"
MESSAGE=$*
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
 
echo -e "SEND TELEGRAM NOTIFICATION..."
 
while ! ping -c 1 192.168.1.20 | grep 'time=' > /dev/null ; do
  echo -e ">   Waiting internet connection..."
  sleep 1
done
echo -e ">   Internet connection found!"
 
echo -e ">   Send telegram notification..."
curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MESSAGE" > /dev/null
 
#for n in 1 2 ; do
#      for f in 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600; do
#        beep -f $f -l 20
#      done
#done
 
echo -e "DONE."

Ora basta aggiungere un richiamo allo script all'interno del file /root/.bashrc.
Ad esempio:

.bashrc
# This file is auto-generated by openmediavault (https://www.openmediavault.org)
# WARNING: Do not edit this file, your changes will get lost.
 
# Enable bash completion in interactive shells.
# Added by openmediavault.
if ! shopt -oq posix; then
    if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
    elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
fi
 
alias ls="ls --color"
 
/root/telegram_notify/send_generic_telegram_notify "NAS - E' stato eseguito un accesso via SSH"
linux/openmediavault/avviso_ad_ogni_login.txt · Ultima modifica: 2021/01/02 11:14 da 127.0.0.1