Bash: History appending for multiple sessions

Posted on

I got a requirement for listing all the command history if  multiple terminal sessions using in different region for the single user. I followed the below steps.

step1 : Create a new file with the below entries

root@appserver:# cat /etc/profile.d/bash_history.sh
function share_history {
 history -a
 history -c
 history -r
}
HISTSIZE=99999
HISTCONTROL=ignoredups
HISTTIMEFORMAT=`echo -e "33[1;34m%d/%h/%Y 33[1;31m%H:%M:%S 33[0m"`
PROMPT_COMMAND='share_history'
shopt -u histappend

Step2: activate it in run-time

root@appserver:# source /etc/profile.d/bash_history.sh

Now you can see the list of aged histories

Sample Output :

1005 26/Dec/2013 14:23:08 vi /etc/profile.d/bash_history.sh
1006 26/Dec/2013 14:23:27 source /etc/profile.d/bash_history.sh
1007 26/Dec/2013 14:23:31 history
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s