How to add secondary logging linux shell

GO to edit /tc/profile

vi /etc/profile

Now you need to add this lines:

# secondary logging linux shell
export HISTSIZE=5000
From=$(who am i| awk '{print $1}')
TO=$(whoami)
[ -d /var/log/history/$TO ] || mkdir -p /var/log/history/$TO
chmod 700 /var/log/history/$TO
export PROMPT_COMMAND=' echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1) " >> /var/log/history/$TO/.bash_history.$From.$TO.$(date "+%Y-%m-%d") '

All users will be tracked in that directory.

Here you have the example results:

$ ll /var/log/history/
total 8
drwx------ 2 root   root   4096 Jul 23 11:03 root
drwx------ 2 test test 4096 Jul 23 11:03 test
[root@vmbs ~]$
$ cat /var/log/history/test/.bash_history.test.test.2021-07-23
2021-07-23.11:03:08 /home/test    22  sudo -i
2021-07-23.11:03:18 /home/test    22  sudo -i
2021-07-23.11:03:39 /home/test    23  less history/test/.bash_history.test.test.2021-07-23
2021-07-23.11:03:50 /home/test    24  sudo yum update
2021-07-23.11:09:51 /home/test    25  less history/test/.bash_history.test.test.2021-07-23
2021-07-23.11:10:08 /home/test    26  ll history/
[root@vmbs ~]$

Enjoy the secondary logging linux shell.