From 2a9bb06a829b73679df63d3afa23c94186ccd6ca Mon Sep 17 00:00:00 2001 From: TKE Date: Fri, 3 Dec 2021 14:18:24 +0100 Subject: [PATCH] Add terminal-logs.sh for terminal transcripts --- terminal-logs.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 terminal-logs.sh diff --git a/terminal-logs.sh b/terminal-logs.sh new file mode 100644 index 0000000..a92d53b --- /dev/null +++ b/terminal-logs.sh @@ -0,0 +1,35 @@ +disablefile=$(realpath ~/.notermlogs) +if [[ -f "${disablefile}" ]] ; then + echo "${disablefile} exists > Terminal - Logging is disabled" +else + if [[ -z "${termlogpid}" ]] ; then + export termlogpid="$(echo $$)" + export termlogsdir="${HOME}/termlogs" + export termlogfilename="${termlogsdir}/$(date +%Y-%m-%d_%H:%M:%S)_${termlogpid}" + if ! [[ -d "${termlogsdir}" ]] ; then + echo "Terminal log folder does not exist. ${termlogsdir} will be created..." + mkdir -v -p "${termlogsdir}" + fi + #Cleanup old files + echo "Removin Terminal Logs older than 30 days:" + find "${termlogsdir}" -type f -mtime +30 + find "${termlogsdir}" -type f -mtime +30 -delete + + #prepare outputfiles with proper permissions + touch "${termlogfilename}.termlog" + chmod 600 "${termlogfilename}.termlog" + touch "${termlogfilename}.termtime" + chmod 600 "${termlogfilename}.termtime" + #start logged session + script -t"${termlogfilename}.termtime" "${termlogfilename}.termlog" + #clean up after exiting + gzip "${termlogfilename}.termlog" + if [[ -f "/tmp/disablescreenrecord_${termlogpid}" ]] ; then + echo "Recording stopped for this session" + else + exit + fi + else + alias stop_termlog="touch /tmp/disablescreenrecord_${termlogpid} ; exit" + fi +fi \ No newline at end of file