Created
July 20, 2013 16:16
-
-
Save cuibonobo/6045590 to your computer and use it in GitHub Desktop.
Get an email whenever someone SSH's into your computer. (Taken from http://apple.stackexchange.com/questions/45688/getting-notified-when-someone-logs-into-a-server-using-ssh-or-remote-desktop/45705#45705)
This file contains 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 | |
mm=`date +%b` | |
dd=`date $1 +%d` | |
dd=`expr $dd` | |
if [ "$dd" -ge "10" ] | |
then | |
dt=`echo "$mm $dd"` | |
else | |
dt=`echo "$mm $dd"` | |
fi | |
cat /var/log/secure.log | grep -E '(Accepted|SUCCEEDED)'| grep "$dt" >> /tmp/access_granted | |
/usr/bin/mail -E -s "Access granted" email@myserver.com < /tmp/access_granted | |
rm /tmp/access_granted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment