How To Log All Bash Sessions Ver0.1
How To Log All Bash Sessions Ver0.1
Notes:
======
1) Replace "username" in LOGDIR below with actual username or change to whatever
location you prefer. Please make sure the directories for LOGDIR and TIMDIR already
exist.
2) playsession script can be passed a session Logfile name (without the extension)
and a Speed up Factor (Divisor) after the Logfile name.
3) If you are using .bash_profile to change/modify any enviornment varialbles
please do so before calling .bashrc otherwise they will not be available in
the nested Shell which gets logged.
4) You will have to logout twice (i.e. exit twice) to close the Cygwin Terminal.
###############################################################################
#Create a ".logrc" file in your home directory with the following lines in it
# File to store location of Session Logs and Timing Files
LOGDIR="/cygdrive/c/Users/username/Documents/Cygwin Terminal Logs/"
TIMDIR="$LOGDIR""Timing Files/"
LOGFILE="Session-$(date +%Y%m%d-%H%M%S-%N)"
###############################################################################
#Create a "bin/logsession" file in your home directory with the following lines
#in it and make the file executable.
#!/bin/bash
#File to initiate the session logging to a log file
if [ -f "${HOME}/.logrc" ] ; then
source "${HOME}/.logrc"
#
# Check if user initiated request for session logging and start the logging file
#
if [ $0 == "${HOME}/bin/logsession" ] ; then
/usr/bin/script --timing="$TIMDIR""$LOGFILE.tm" "$LOGDIR""$LOGFILE.log"
#
# Session logging not initiated by user (i.e. initiated by .bashrc)
# Check if this is topmost SHELL (to avoid recursive loop) and start logging file
#
elif [ $SHLVL == 1 ] ; then
/usr/bin/script --timing="$TIMDIR""$LOGFILE.tm" "$LOGDIR""$LOGFILE.log"
fi
fi
###############################################################################
#Create a "bin/playsession" file in your home directory with the following lines
#in it and make the file executable.
#!/bin/bash
if [ -f "${HOME}/.logrc" ] ; then
source "${HOME}/.logrc"
#
# Check if user passed a speedup factor
#
if [[ $2 ]] ; then
echo
echo "********** Starting playsession for $1 at $2X Speed **********"
echo
/usr/bin/scriptreplay --timing="$TIMDIR""$1.tm" "$LOGDIR""$1.log" "$2"
echo
echo "********** Finished playsession for $1 at $2X Speed **********"
echo
#
# No speedup factor
#
else
echo
echo "********** Starting playsession for $1 **********"
echo
/usr/bin/scriptreplay --timing="$TIMDIR""$1.tm" "$LOGDIR""$1.log"
echo
echo "********** Finished playsession for $1 **********"
echo
fi
fi
###############################################################################
#Add the following lines at the end of your ".bashrc" file in your home directory.
# Log all the session output to a log file
if [ -f "${HOME}/bin/logsession" ] ; then
source "${HOME}/bin/logsession"
fi