Created
February 1, 2012 01:21
-
-
Save khansensf/1714374 to your computer and use it in GitHub Desktop.
Email terminal history to self / evernote at logout. Great for search for obscure syntax you figured out sometime on some machine
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 | |
################## | |
# MailHistory.bash | |
# Ken Hansen 01/2010 | |
# | |
# Calc history delta then email to self and evernote | |
# | |
# Called from ~/bash_logout | |
# | |
# Saves history in ~.history.old for comparison next time around | |
# | |
################## | |
# Email addresses to send transcript to | |
EMAIL_ADDRS="[email protected] [email protected]" | |
# remove all aliases (to make sure any alias of rm is removed) | |
unalias -a | |
# Clean up any old files | |
if [ -f ~/.history.new ] | |
then | |
rm -f ~/.history.new | |
fi | |
if [ -f ~/.history.diff ] | |
then | |
rm -f ~/.history.diff | |
fi | |
# make sure there is a history.old to diff | |
if [ ! -f ~/.history.old ] | |
then | |
touch ~/.history.old | |
fi | |
# Save history to history.new | |
/usr/bin/grep -v \# ~/.bash_history > ~/.history.new | |
# diff new and old | |
diff ~/.history.new ~/.history.old | grep '<' | sed -e "s/< //g" > ~/.history.diff | |
# move new to old for next time | |
rm -f ~/.history.old | |
mv ~/.history.new ~/.history.old | |
#### | |
# Caluclate email subject | |
# Get host hame | |
host=`/bin/hostname | /usr/bin/sed 's/\..*//'` | |
# Calculate date (e.g., Thu 02/25/10 10:30:42 PM0 | |
dtstring=`/bin/date '+%a %m/%d/%y %I:%M:%S %p'` | |
subject="@TermHistory Diff $host $dtstring #History" | |
# mail history to evernote | |
/usr/bin/mailx -s "$subject" $EMAIL_ADDRS < ~/.history.diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment