Managing Linux Servers ? Recieve An Email When Someone Logs Into your Server!
You can send out an “alert” email when someone logs in to your server (or workstation) by taking two steps*.
Step 1) is done by placing this script into a file named “iloggedin” the /usr/local/sbin/ directory, and making it executable with chmod +x /usr/local/sbin/iloggedin. While you are creating the file, make sure to modify the RECIPIENT declaration on line 2 so that it points to the email address at which you want to receive alerts. Once you do this, you’re half way done…
#!/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 < Remote user $USER just logged in to $HOST at $TIME from $REMOTEIP
LOGGEDIN
exit $?
Step 2) is to modify your /etc/profile file. Add the following line to the bottom of the file:
/usr/local/sbin/iloggedin >/dev/null 2>&1 & disown -a
*You will need to have a working email setup before you can send mail from your Linux operating system.
This concludes our little howto.
from : http://www.atrixnet.com/send-an-email-when-someone-logs-in/