Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active December 8, 2017 01:28
Show Gist options
  • Save heywoodlh/c4a37e1f3bae55bfd9ff4e23968f7a73 to your computer and use it in GitHub Desktop.
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
#!/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