Initial commit

This commit is contained in:
yigid balaban 2024-09-18 00:23:17 +03:00
commit c3497a7a2a
Signed by: fyb
GPG Key ID: CF1BBD1336C0A3D6

26
login mailer.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
#
# Yigid BALABAN, <fyb@fybx.dev>
# login mailer
#
# set env var EMAIL and ENDPOINT
LOG_FILE="/var/log/auth.log"
HOSTNAME=$(hostname)
if [[ ! -f "$LAST_LINE_FILE" ]]; then
echo "0" >"$LAST_LINE_FILE"
fi
LAST_LINE=$(cat "$LAST_LINE_FILE")
NEW_LINES=$(sed -n "$((LAST_LINE + 1)),\$p" "$LOG_FILE")
if echo "$NEW_LINES" | grep "sshd.*Accepted"; then
LOGIN_INFO=$(echo "$NEW_LINES" | grep "sshd.*Accepted" | awk '{print $9 " from " $11}')
curl -H "content-type: application/json" \
-d "{\"subject\": \"New login on $HOSTNAME\", \"text\": \"SSH login detected: $LOGIN_INFO\", \"recipient\": \"$EMAIL\"}" \
"$ENDPOINT"
fi
wc -l <"$LOG_FILE" >"$LAST_LINE_FILE"