Linux Server Login Alert Script
The following script demonstates a way to send out an alert email when someone logs in the Linux Server.
vi /script/login_alert.sh
#!/bin/bash
host=`hostname`
user=`whoami`
ip="$(echo $SSH_CLIENT|awk '{print $1}')"
mkdir -p ~/ServerLoginTrace
echo 'ALERT - ' $user ' IP:'$ip ' Shell Access' $host > ~/ServerLoginTrace/alert_message.txt
pinky >> ~/ServerLoginTrace/alert_message.txt
chmod 600 ~/ServerLoginTrace/alert_message.txt
mutt -s "Login Monitor from $host" -- danbrother@pixnet.net < ~/ServerLoginTrace/alert_message.txt
echo ". /script/login_alert.sh > /dev/null 2>&1 &" > /etc/ssh/sshrc
chown root:dba /etc/ssh/sshrc
chmod 770 /etc/ssh/sshrc
$ cat ~/ServerLoginTrace/alert_message.txt
ALERT - danbrother IP:168.95.1.101 Shell Access MyTestServer
Login Name TTY Idle When Where
danbrother pts/0 Mar 5 10:22 168.95.1.101