Last active
August 29, 2015 14:17
-
-
Save korovamilk/4d343cffccaf6a98f517 to your computer and use it in GitHub Desktop.
Add this to .bashrc of user. When user logs in (via ssh or console), you receive an e-mail at ${DEST_EMAIL}
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
### add this to .bashrc | |
DEST_EMAIL="[email protected]" | |
TMPCOOKIE="/tmp/cookie.$(date +%y%m%d%H%M%S)" | |
CONNIP=$(echo $SSH_CONNECTION | cut -d " " -f 1) | |
touch ${TMPCOOKIE} | |
if [ -z "$CONNIP" ] | |
then | |
echo "${HOSTNAME}: User $USER just logged in from console" >> ${TMPCOOKIE} | |
echo >> ${TMPCOOKIE} | |
w >> ${TMPCOOKIE} | |
mail -s "ssh login at ${HOSTNAME}" ${DEST_EMAIL} < ${TMPCOOKIE} | |
rm -f ${TMPCOOKIE} | |
else | |
echo "${HOSTNAME}: User $USER just logged in from $CONNIP" >> ${TMPCOOKIE} | |
echo >> ${TMPCOOKIE} | |
w >> ${TMPCOOKIE} | |
mail -s "ssh login at ${HOSTNAME}" ${DEST_EMAIL} < ${TMPCOOKIE} | |
rm -f ${TMPCOOKIE} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment