Last active
September 4, 2020 20:51
-
-
Save nelbren/15bfe090c0c87ad97b8a8dae96b40680 to your computer and use it in GitHub Desktop.
spy.sh
This file contains hidden or 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 | |
# spy.sh - 2020-09-04 - gist.github.com/nelbren | |
# https://www.thomaslaurenson.com/blog/2018/07/02/better-bash-history/ | |
export HISTFILESIZE=-1 | |
export HISTSIZE=-1 | |
export HISTCONTROL=ignoredups | |
export HISTTIMEFORMAT='%F %T ' | |
export HISTIGNORE="./.itsme.bash" | |
PROMPT_COMMAND='history -a' | |
shopt -s cmdhist | |
shopt -s lithist | |
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$"\n"}history -a; history -c; history -r" | |
set +m | |
shopt -s lastpipe | |
base=/tmp/.spy.$USER | |
log=$base.log | |
hist_log=$base.hst | |
hist_temp=$base.hst.temp | |
hist_diff=$base.hst.diff | |
hist=~/.bash_history | |
cp ~/.bash_history $hist_temp | |
echo "" >> $log | |
echo "WHAT?" >> $log | |
echo "" >> $log | |
echo "history" >> $log | |
echo "-------" >> $log | |
diff -au $hist_log $hist_temp | egrep -a "^\+" | egrep -av "\+\+\+" | sed "s/^+//" | tee -a $hist_log 2>$hist_diff 1>&2 | |
nc=0 | |
cat $hist_diff | \ | |
while read linea; do | |
if [[ $linea =~ ^#[0-9]{10}$ ]]; then | |
echo -n "$(date -d @${linea:1} '+%Y-%m-%d %T')" >> $log | |
else | |
nc=$((nc+1)) | |
echo " $linea" >> $log | |
fi | |
done | |
echo "" >> $log | |
echo "$nc comando(s) encontrado(s)" >> $log | |
echo "" >> $log | |
echo "WHEN?" >> $log | |
echo "" >> $log | |
echo $(date +'%Y-%m-%d %H:%M:%S') >> $log | |
echo "===================" >> $log | |
echo "" >> $log | |
echo "WHO?" >> $log | |
echo "" >> $log | |
echo "who am i" >> $log | |
echo "--------" >> $log | |
who am i >> $log | |
echo "" >> $log | |
echo "id" >> $log | |
echo "--" >> $log | |
id >> $log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment