#!/bin/csh -f #H# Logs my terminal sessions #H# Usage: #H# logterm [hostname] [connection command] [additional parameters] #H# #H# The first 2 parameters are required. #H# The hostname supplied will be used in the logfile path and in the connection command. #H# The connection command is whatever tool is used to connect to the host. #H# #H# If you were to type: #H# logterm asylum ssh -C -l kmk #H# logterm will actually run: #H# ssh -C -l kmk asylum | tee [logdir]/asylum/[date] #H# Once the logged program exits the logfile will be gzipped. # print usage info if needed if ($1 == "-h" || $1 == "--help" || $1 == "help" || $1 == "") exec sed -n -e '/^\#H\#/s/^....//p' $0 # Get the data that will be used in the file name set HOST=$1 set DATE=`/usr/bin/date +%Y-%m-%d_%H:%M:%S` set LOGDIR="$HOME/docs/terminal_logs/$HOST" # Make the directory that the log will go into just in case /bin/mkdir -p $LOGDIR >& /dev/null # This will be the actual log file name set LOGFILE="${LOGDIR}/$DATE" # Throw a -1 on the file name if one already exists with that name. # NOTE that this should be fixed as it does file-1-1-1-1-1 if it keeps colliding while -e $LOGFILE set LOGFILE="${LOGFILE}-1" end # Run the command that will be logged and log it # I know this syntax is very ugly but I need $1 to be at the opposite end so I can't # just use $* :( $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30 $31 $32 $33 $34 $35 $36 $37 $38 $39 $40 $HOST |& /usr/bin/tee $LOGFILE # Gzip off the file now that I am done putting stuff in it exec /usr/bin/gzip -9fv $LOGFILE