This repository has been archived on 2023-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
awesome-scripts/login-notify.sh

18 lines
593 B
Bash
Raw Permalink Normal View History

2020-05-20 23:57:45 +00:00
#!/bin/bash
2020-09-30 19:27:49 +00:00
GOTIFY_FILE=$(<~/.gotify)
GOTIFY_TOKEN=${GOTIFY_FILE##*( )}
HOST="$(hostname)"
2021-05-15 22:27:56 +00:00
sender="SSH-Notification <mail>"
recipient="<mail>"
2020-09-30 19:27:49 +00:00
subject="SSH Login: $PAM_USER from $PAM_RHOST on $HOST"
message="User $PAM_USER logged in on $HOST from $PAM_RHOST at $(date)."
2020-05-20 23:57:45 +00:00
2020-09-30 19:27:49 +00:00
if [ "$PAM_TYPE" == "open_session" ]; then
if [ -n "$GOTIFY_TOKEN" ]; then
curl -F "title=$subject" -F "message=$message" -F "priority=5" "https://push.sp-codes.de/message?token=$GOTIFY_TOKEN"
2020-10-05 17:50:34 +00:00
elif [ "$PAM_USER" != "root" ]; then
echo "$message" | mailx -a "From: $sender" -s "$subject" "$recipient"
2020-09-30 19:27:49 +00:00
fi
2020-05-20 23:57:45 +00:00
fi