Last active
December 8, 2017 01:28
-
-
Save heywoodlh/c4a37e1f3bae55bfd9ff4e23968f7a73 to your computer and use it in GitHub Desktop.
Script to notify if a login is detected from an admin user on a computer
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
| #!/usr/bin/env bash | |
| ADMINISTRATOR1="admin_user1" | |
| ADMINISTRATOR2="admin_user2" | |
| MY_IP="$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}')" | |
| MY_IP="$MY_IP" | |
| ACCOUNTS="$(who)" | |
| if echo "$ACCOUNTS" | grep --quiet -e "$ADMINISTRATOR1" -e "$ADMINISTRATOR2" | |
| then | |
| ACCOUNT="$(echo $ACCOUNTS | grep -oh -e $ADMINISTRATOR1 -e $ADMINISTRATOR2)" | |
| MESSAGE="$ACCOUNT logged in to $MY_IP" | |
| curl -X POST -H 'Content-type: application/json' \ | |
| --data "{\"text\":\"$MESSAGE\"}" \ | |
| https://hooks.slack.com/services/XXXXXXXXXXXXXXX/OOOOOOOOOOOOOOOOOOO | |
| echo "$MESSAGE" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment