Run "history" as another user to show their history

T

Thierry Montalbano

Guest
Hi,

I would like, as root, to be able to enhance the output of the command "history" by adding timestamps and the username of the person who run that command.

To do such a thing, I have already found some stuff online, more or less complicated, the easiest possibly being to edit the bash_profile of each users with:
original_user=${SUDO_USER:-$(pstree -Alsu "$$" |
sed -n "s/.*(\([^)]*\)).*($USER)[^(]*$/\1/p")}
export HISTTIMEFORMAT="<%F %T> (${original_user:-$USER}) [$$] "

Then indeed, if I log under any user and run history, I'll have an output like this:



8 <2014-10-20 16:04:11> (root) [24143] vim /etc/rsyslog.
9 <2014-10-20 16:04:14> (root) [24143] vim /etc/rsyslog.conf
10 <2014-10-20 16:04:57> (root) [24143] /etc/init.d/rsyslog restart
11 <2014-10-20 16:16:41> (root) [24143] history

Based from that, I'd like to make a script that would collect all the bash history file and merge them in a single output.


For that, my idea is to run the command "history" under each user, but it does not seem to work with:



[root@test-thierry ~]# su -l tmontalb -c "history"
[root@test-thierry ~]#

Does anybody have any idea if this is possible or can suggest me something that would not take much to install? I thought it'd be very simple to add the username and timestamp in the output of the command "history".

Thank you.
Thierry.
 

Members online


Top