Skip to content

Instantly share code, notes, and snippets.

@tommybutler
Created October 12, 2013 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tommybutler/6953743 to your computer and use it in GitHub Desktop.
Save tommybutler/6953743 to your computer and use it in GitHub Desktop.
See this page for details and usage instructions: http://www.atrixnet.com/send-an-email-when-someone-logs-in/
#!/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 $?
@eznode
Copy link

eznode commented Nov 13, 2018

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment