Posted Feb 7, 05:59 AM by ben
I don’t understand why modern terminals (with exception of putty) do not allow for logging.
I successfully use my e-mail history and IM logs to great extent when doing post mortems or other general reports. I should have that same functionality at my command prompt. And something a little more useful than “cat ~/.history”. Script is handy for this (though an unfortunately hard name to google for). But I want to not have to worry about those pesky filenames so I did up a quick startlog script.
#!/usr/local/bin/bashLOGDIR=”/home/ben/logs/” #where we store teh logs
ITERATION=0 #start off at 0
STARTED=0
DATE=`date “+%F”`
if [ -n “$1” ] #this is what the filename will be prefixed with
then
PREFIX=$1
else
PREFIX=“log”
fi#echo -n “$PREFIX”
while [ “$STARTED” -eq “0” ]
do
ITERATION=$((ITERATION+1))
if [ !
e $LOGDIR$PREFIX$DATE-$ITERATION.log ]
then export LOGFILE=”$LOGDIR$PREFIX-$DATE-$ITERATION.log” script $LOGFILE echo -n “Logging to $LOGFILE” STARTED=1
fi
done
I set my PS1 prompt to also show the current time to allow me to have everything timestamped. And, handily enough, I export the log filename to the shell which leads to a new alias in .bashrc:
alias sendlog=“cat $LOGFILE | mail -s ‘$LOGFILE Transcript’”
I haven’t actually used this yet but the novelty of it is handy. On a downside, cygwin does not have script which is a real bummer.
I still think this functionality should be built into rxvt, gnome-terminal, konsole, terminal.app, etc. Don’t even get me started on cmd.exe “featureset”.
// :: handy-tools/
Commenting is closed for this article.

This work by http://electricfork.com is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
I lead an information security ops and response team. This site is a collection of interesting notes and brainstorms on the protecting from, detecting of, and responding to badness. You can read more about me or my site here.
You can subscribe to my blog via rss
, or if you're looking for older items check out my archive of previous posts.
I organize a small infosec meetup in baltimore called charmsec. If you are looking for charmsec details you probably want to go here.
RSS