Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I found the following command:

history | tail -20 | mail -s "log `hostname` pada `date`" mailid[at]corporate.com

I want to combine it with an automatic logout script: The system should send an email alert when the root user has logged out from SSH/terminal. The mail should have the date and include the output of the aforementioned command.

share|improve this question
    
You do realize that users can just wipe or edit their history before logging out? –  Daniel Beck Aug 15 '13 at 9:17
    
To do user monitoring right, you could use e.g. sudosh and give nobody the root password -- only allow sudo sudosh. Make sure to contact your legal department before you do this though. –  Daniel Beck Aug 15 '13 at 9:19
    
yes, i do because my server not use sudo. so why i must log this when user root logout the system must send alert with history, what the command to do that? –  user2684891 Aug 15 '13 at 11:32

1 Answer 1

Bash executes at logout the script .bash_logout in the user home dir and /etc/bash.bash_logout (which is run for all users). Basically you could put the command you have in /root/bash_logout and have it execute whenever a login shell for user root exits.

However, it will only work when bash is the shell being used and as long as nobody using root account is not removing those commands from the file, so security-wise this is not really useful (if that is what you had as motivation for this) [Upd: as others already commented].

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.