Добавить paranoia-shutdown.sh

This commit is contained in:
2025-12-04 17:43:49 +03:00
parent 0d9846ec88
commit bbbb5d95bf

47
paranoia-shutdown.sh Normal file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
allowIp=$2
pidFile="/var/run/paranoia-shutdown.pid"
start(){
echo $$ > "$pidFile"
tail -f -n0 /var/log/auth.log | while read string
do
if echo "$string" | grep "Accepted password for"
then
ip=$(echo "$string" | grep -o -E '([0-9]{1,3}[\.]){3}[0-9]{1,3}')
if [ "$ip" != "$allowIp" ]
then
logger "Alert!!! Alert!!! Alert!!! Login from not confirmed ip $ip. Faster shutdown!"
systemctl poweroff
fi
fi
done
}
stop(){
kill $(cat "$pidFile")
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 3
esac