Configure Bash Track Log for Linux


✪To configure Bash Track Log in Linux please follow the following steps

1. Create log format in bashrc file (By adding the below value to the end of file)
Ubuntu/Debian: /etc/bash.bashrc,  Centos/Redhat: /etc/bashrc

export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: \
 $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

2. Create log file path (Adding below value to file)
 vim /etc/rsyslog.d/bash.conf  

local6.* /var/log/bash_track.log

3.Create logrotate file (Adding below value to file)
 vim /etc/logrotate.d/bash

/var/log/bash_track.log {
        su root adm
        daily
        rotate 60
        compress
        delaycompress
        missingok
        notifempty
        create 0640 root root
    }

4.Restart rsyslog service
For Ubuntu/Debian
# /etc/init.d/rsyslog restart
For Redhat/CentOS/Fedora
# systemctl restart rsyslog

📓 Bash track log file will write in /var/log/bash_track.log and rotate everyday (daily)

Thank you!🦆

Comments