Skip to content

Instantly share code, notes, and snippets.

@SafeAF
Forked from tommybutler/iloggedin.sh
Last active August 29, 2015 14:23
Show Gist options
  • Save SafeAF/4313693b9f4792a9912f to your computer and use it in GitHub Desktop.
Save SafeAF/4313693b9f4792a9912f to your computer and use it in GitHub Desktop.
#!/bin/bash
RECIPIENT="your.email@address.here";
PREFIX="LOGIN ALERT!";
REMOTEIP=$(/bin/echo $SSH_CLIENT | /usr/bin/awk '{ print $1 }');
TIME=$(/bin/date +'%r, %D');
HOST=$(/bin/hostname -f);
if [[ "$REMOTEIP" == "" ]]; then
REMOTEIP='localhost';
fi
/bin/cat <<LOGGEDIN | /usr/bin/mail -s "$PREFIX $USER@$HOST $TIME" $RECIPIENT
Remote user $USER just logged in to $HOST at $TIME from $REMOTEIP
LOGGEDIN
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment