diff --git a/paranoia-shutdown.sh b/paranoia-shutdown.sh new file mode 100644 index 0000000..635a062 --- /dev/null +++ b/paranoia-shutdown.sh @@ -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