Created
October 29, 2015 18:48
-
-
Save ardichoke/038c84b7966856da211a to your computer and use it in GitHub Desktop.
Eternal bash logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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