Logfuse Environment
  • function:

log all command and output into ~/.logfuse

  • usage:

add the following line into bash_profile or /etc/profile

. /etc/logfuse_profile

  • problem:

change user command which like su could produce duplicated output to the log of before and after shell.

/etc/logfuse_profile

#!/bin/bash
# logfuse_profile
 
if [ "$LOGFUSE_STARTED" = "" ] ; then
{
 
if [ ! -d ~/.logfuse/bash ] ; then
        mkdir -p .logfuse/bash
fi
 
find ~/.logfuse/bash -atime +365 -exec \rm {} \;
 
LOGFILE_BASENAME=~/.logfuse/bash/bashrc_`date '+%Y%m%d%H%M%S'`
 
LOGFILE_ADDNAME=000
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
LOGFILE_ADDNAME=001
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
LOGFILE_ADDNAME=002
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
LOGFILE_ADDNAME=003
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
LOGFILE_ADDNAME=004
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
LOGFILE_ADDNAME=005
LOGFILE_NAME=${LOGFILE_BASENAME}_${LOGFILE_ADDNAME}.log
if [ -f $LOGFILE_BASENAME ] ; then
 
        echo TOO MANY bash, more than 5, started on `date '+%Y/%m/%d %H:%M:%S'`. logfuse for bash is disabled. 1>&2
 
fi
 
fi
 
fi
 
fi
 
fi
 
fi
 
        export LOGFUSE_STARTED=1
} >> ~/.logfuse.log 2>&1
 
        echo [`date '+%Y%m%d%H%M%S'`] `who am i` `whoami` `pwd` > $LOGFILE_NAME
        echo `last` > $LOGFILE_NAME
        . ~/.bash_profile
        script -aqf $LOGFILE_NAME
        #script -aqtf $LOGFILE_NAME
 
        export LOGFUSE_STARTED=
        exit
 
else
        echo start monitored shell >> ~/.logfuse.log
        export LOGFUSE_STARTED=
        #. ~/.orgn_bashrc
fi