Last active
July 18, 2021 18:02
-
-
Save a-maumau/1d85362449dd5771ddfbe9106b201d3f to your computer and use it in GitHub Desktop.
notify login via slack on linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# you also need to set this script in `pam.d/<what you want>`. | |
# for example, | |
# in file `/etc/pam.d/common-password` | |
# add following: | |
# | |
# session optional pam_exec.so /usr/local/bin/notify_login.sh | |
# | |
# the file names under the `pam.d` may differ in OS and version, | |
# please suit your enviroment. | |
HOST_NAME="host_name" | |
SLACK_WEBHOOK_API_URL='your_slack_webhook_url' | |
USER_NAME="user: $PAM_USER" | |
#RUSER="Ruser: $PAM_RUSER" | |
REMOTE_HOST="from: $PAM_RHOST" | |
#SERVER_NAME="server: `uname -a`" | |
SERVICE="Service: $PAM_SERVICE" | |
TTY="TTY: $PAM_TTY" | |
DATE="Date: `date`" | |
if [ "$PAM_TYPE" = "open_session" ]; then | |
JSON="{ \"text\": \"\`[LOGIN][$HOST_NAME]\`\n\`\`\`$DATE\n$USER_NAME\n$REMOTE_HOST\n$SERVICE\n$TTY\`\`\`\" }" | |
RET=`curl -s -X POST -H 'Content-Type: application/json' -d "$JSON" $SLACK_WEBHOOK_API_URL` | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment