sudo -e /etc/bashrc
and add this line:
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" )"'
source /etc/bashrc
vim /etc/rsyslog.d/bash.conf
and add the following line:
local6.* /var/log/commands.log
vim /etc/logrotate.d/syslog
and add the following line:
/var/log/commands.log
systemctl restart rsyslog
For BASH shells, edit the system-wide BASH runtime config file:
vim /etc/bash.bashrc
Append to the end of that file:
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
Set up logging for "local6" with a new file:
vim /etc/rsyslog.d/bash.conf
contents...
local6.* /var/log/commands.log
Restart rsyslog:
systemctl restart rsyslog
source /etc/bash.bashrc or logout/login
log rotation:
vim /etc/logrotate.d/rsyslog
Add the new bash-commands log file to the list:
/var/log/commands.log