Hi,
Do you want an email alert if someone access your server.?. then you can follow the steps and execute the following script.
Create a file say file.txt and add the following contents to it.
#vi file.txt
echo 'ALERT - User `whoami` Shell Access on:' `date` `who` | mail -s "Alert: `whoami` Access from `who | awk '{print $6}'`" user@yourdomain.com
then execute the following script to make the file.txt contents to be copied to all user’s .bash_profile file.
#!/bin/bash
for file in $(find / -name .bash_profile)
do echo `cat file.txt` >> $file done
then add the line "echo 'ALERT - User `whoami` Shell Access on:' `date` `who` | mail -s "Alert: `whoami` Access from `who | awk '{print $6}'`" user@yourdomain.com" to "/etc/skel/.bash_profile" this will automatically add the above line to all the new user's .bash_profile file.
That’s it you will be noted through mail if someone logins to your server.
Thanks for viewing helpinlinux.com
I added the line to my /etc/bash.bashrc.local file.
This file gets executed for every user that logs in at least with a bash shell, which is what I’m interested in.
Also please note unicode characters if you copy and paste from this webpage:
echo “ALERT – User `whoami` Shell Access on:” `date` `who` | mail -s “Alert: `whoami` Access from “who | awk ‘{print $5}’`” user@yourdomain.com