History of all the users in single file with command , date . time , ip and user

HTML Code

archive_history() {     HISTORYOLD=${HISTFILE}.archive     CURTIME=`date`     CURTTY=`tty`     IP=$(echo $SSH_CLIENT | awk '{print $1}')        if  [ x$HISTDUMPPED = x ]; then                echo "#-${HOSTNAME}-- ${CURBASHDATE} - ${CURTIME} ($CURTTY) ${USER} ${IP}----" >>   $HISTORYOLD       history $(($HISTCMD-${CURBASHSTART-0})) | sed -e 's/^[ ]*[0-9][0-9]* [ ]*//g'  >> $HISTORYOLD       export HISTDUMPPED=1     fi }  exit () {    archive_history    builtin exit }

then add following line in .bash_logout in each user home's dir.

vi /home/oracle/ .bash_logout

archive_history >>  .bash_logout

you can see all details by like " command date ipaddress/username"
after doing above all step once login, run some command and then logout and then login
and then check "cat .bash_history.archive"

with your script i am getting output like this :

cat /home/oracle/.bash_history.archive
#-test2.fatima-group.com-- - Thu Mar 27 17:38:23 PKT 2014 (/dev/pts/2) oracle 10.1.8.226----
2014-03-27 17:38:23 logout
#-test2.fatima-group.com-- - Thu Mar 27 17:41:11 PKT 2014 (/dev/pts/4) oracle 10.1.8.244----
2014-03-27 17:41:11 logout
#-test2.fatima-group.com-- - Thu Mar 27 17:52:02 PKT 2014 (/dev/pts/3) oracle 10.1.8.226----
2014-03-27 17:52:02 logout

There are 2 problems , i mean which i want to fulfill my requirement

Problem 1 : i am not getting command which is executed by user

problem2 : i should get all details in .bash_history.archive even if i close my terminal ( i mean i just close my ssh terminal and dont type exit or logout )

thanks in advance

Many installations will do something like this to collect users history...

http://www.adeptus-mechanicus.com/codex/histsys/histsys.html

How about just observing the /var/log/messages file.
Depending on you *nix flavour this may be a different file. This file has entries like

Mar 27 17:04:30 <hostname> sshd[17857]: pam_unix(sshd:session): session closed for user user1
Mar 27 17:04:48 <hostname> sshd[20711]: Connection closed by <ip_address>