Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send a mail on root loggin

Status
Not open for further replies.

LeDam

IS-IT--Management
Oct 10, 2001
210
BE
Hello,
Can somebody tell me if it's possible to send a mail when root loggin into a linux server???
Also when su is use?
 
You could probably setup something in [tt]root[/tt]'s [tt].<shell>rc[/tt] that would send an email to you. This file is read when [tt]root[/tt] logs in. //Daniel
 

There's a programme out there called swatch. It monitors the log files and can do several thing based on log events.

Do a search on 'swatch log'.

Cheers Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
It work fine....
Thanks....
 
Or what I do is edit the root's .profile and add the following line:-

/backups/.logmein 2>&1 /dev/null

the file /backups/.logmein has the following contents:-
#!/bin/bash
email=&quot;someone@mydomain.co.uk&quot;
Date=`/bin/date`
lastlog | mail -s &quot;ROOT Just Logged in at $Date&quot; $email
#end script

Then make it executable for root and every time root logs in a mail will be sent with the body containing the output of lastlog (useful to see where he/she connected from).

A similar process is useful for normal users but just grep off the username from lastlog ?

lastlog | grep fredbloggs | mail -s &quot;Fred Bloggs Just Logged in at $Date&quot; $email

works with &quot;su - <user>&quot; but not with &quot;su <user>&quot; for obvious reasons.
Enjoy
L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top