You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.9 KiB

#!/bin/bash
LOGDIR="/var/log/recordshell"
LOGGING_PID="$$"
FILEPREFIX="$LOGDIR/$(date '+%Y-%m-%d')/$(date '+%Y-%m-%d_%H-%M-%S')-$LOGGING_PID";
CFG_FILE="/etc/recordshell"
TARGET_USER="$1"
#EXTRA_ARGS="-c 'su -c \"/bin/bash -l\" - $TARGET_USER'"
EXTRA_ARGS="-c 'su -s /bin/bash - $TARGET_USER'"
if [ "`whoami`" != "root" ];then
set -x
exec sudo $0 "`whoami`"
set +x
fi
if [ -z "$TARGET_USER" ];then
echo "$0 <target_user>"
exit 1
fi
if ( bash $CFG_FILE &> /dev/null );then
source $CFG_FILE;
else
echo "error in configfile $CFG_FILE"
exit 1
fi
mkdir -p $FILEPREFIX
if [ "$?" != "0" ];then
echo "Unable to create directory structure $FILEPREFIX"
exit 1
fi
SUDO_MSG=""
if [ -n "$SUDO_USER" ];then
SUDO_MSG=", (sudo user $SUDO_USER, sudo command $SUDO_COMMAND)"
fi
echo "*********************************"
logger -s -t recordshell "[$LOGGING_PID] Starting logged shell session: ${FILEPREFIX}/{typescript,timing} $SUDO_MSG"
set -x
eval script $EXTRA_ARGS -e -q -f -t ${FILEPREFIX}/typescript 2>${FILEPREFIX}/timing
set +x
logger -s -t recordshell "[$LOGGING_PID] Finished logged shell session: ${FILEPREFIX}/{typescript,timing} $SUDO_MSG"
echo "*********************************"
gzip ${FILEPREFIX}/typescript
if [ "$?" != "0" ];then
logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/typescript failed"
else
logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/typescript successful (MD5SUM $(md5sum ${FILEPREFIX}/typescript.gz|awk '{print $1}'))"
fi
gzip ${FILEPREFIX}/timing
if [ "$?" != "0" ];then
logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/timing failed"
else
logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/timing successful (MD5SUM $(md5sum ${FILEPREFIX}/timing.gz|awk '{print $1}'))"
fi
logger -s -t recordshell "[$LOGGING_PID] review session with: scriptreplay -t ${FILEPREFIX}/{timing.gz,typescript.gz}"