Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found the following command:

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .