tail -2 /root/.bashrc
export HISTTIMEFORMAT="%d/%m/%y %T "
export PROMPT_COMMAND='builtin history 1 >> /var/log/root.log'
With this all the commands could be logged (even the ones that were in "sudo su -" ).
My question: How can I put username info in the history file, so not just the time will be logged, but the original user, who "sudo su -"'ed username is in the history files too (or process PID from it's shell, or any unique identifier)?
original_user=$(pstree -Alsu "$$" | sed -n "s/^[^\(]*(\([^)]*\)).*($USER)[^(]*$/\1/p")
- in case s/b makessudo -iu <user>
several times – atti Feb 05 '18 at 19:40