email alert on root login

FleroviumUranus

Verified User
Joined
Aug 28, 2012
Messages
94
Location
everwhere
vi .bash_profile
Scroll down to the end of the file and add the following line:


echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]

i follow this but not getting the emails on root login
what i missing?
 
in my root directory
. .. .bash_history .bash_profile .custombuild .rnd setup.sh .ssh


i need to mkdir .bashrc or i an searching on wrong place
 
Hello,

Make sure, your root is using bash

Code:
grep ^root: /etc/passwd | cut -d\: -f7

Then... make sure that the code is working, just put in a file test.sh and run

Code:
sh ./test.sh

you should get an email. If not, then read exim logs.
 
You need to create the file, not the directory.

Do:

Code:
nano ~/.bashrc

and put in there that line

Save and exit

Regards
 
Hello,

Make sure, your root is using bash

Code:
grep ^root: /etc/passwd | cut -d\: -f7

Then... make sure that the code is working, just put in a file test.sh and run

Code:
sh ./test.sh

you should get an email. If not, then read exim logs.

test.sh: line 3: [email protected]: command not found


code
#!bin/bash
echo 'ALERT - Root Shell Access (YourserverName) on:' `date` `who` |
mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`"
[email protected]
 
Yes, Andrea is right, your code should look like this:

Code:
#!bin/bash
echo 'ALERT - Root Shell Access (YourserverName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" [email protected]
 
Back
Top