I currently have a server set up to save Bash history for every user immediately in their respective home folders and I want to create a script that runs on a set interval that switches the current user and executes the "history" command.
I have tried all variants of both su and sudo in the command line but whenever I run the command "history" for another user in a script or usind su/do, I get no output whatsoever.
In scripts, I have tried all variants of both su and sudo, as well as:
su <user>
history
But all it does is open a shell with that user and doesn't return the output of "history".
I'm currently using RHEL6.9 with Bash 4.1.2.
EDIT:
I have a log collector that currently monitors all .bash_history files, but I configured /etc/bashrc to append timestamp and user so I can assign fields and log the exact time execution of each command. Because the internal format that Bash stores command line history in .bash_history is to just add the epoch time, I need to be able to execute "history" on each individual user.
I have tried (separately) the following from the command line, as well as in scripts:
su -c "history" <user>
sudo -i -u <user> history
sudo -S -u <user> -i /bin/bash -l -c 'history'
I have tried to do this in scripts:
su -i <user>
history
But they never return any results.
su - <user>
instead ofsu <user>
. Check out this answer