Skip to content

Instantly share code, notes, and snippets.

@ardichoke
Created October 29, 2015 18:48
Show Gist options
  • Save ardichoke/038c84b7966856da211a to your computer and use it in GitHub Desktop.
Save ardichoke/038c84b7966856da211a to your computer and use it in GitHub Desktop.
Eternal bash logging
#!/bin/bash
function log_cmd
{
local mytty=$(tty | sed 's/\/dev\///')
local host=$(who | grep "$mytty " | sed 's/^.*(\(.*\)).*$/[\1]/')
local user=$(ls -l /dev/${mytty} | awk '{print $3}')
HISTORY="$(history 1)"
if [ "z$HISTORY" != "z" ];
then
if [ "$HISTORY" != "$LASTHISTORY" ];
then
echo "$(date +%Y%m%d-%H%M%S) $user $mytty $host::" "$HISTORY" >> ~/.bash_eternal_history
fi
fi
export LASTHISTORY="$HISTORY"
}
trap "log_cmd 2>/dev/null" DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment