Keeping Track of How Tos

Working at a start-up, I get to wear many hats and gain experience in a wide-range of topics.

But that also means picking up a project, learning skills needed to complete it, then moving on to the next project which may not require any of the knowledge I just acquired. For example, as part of an Incident Response project last year, I needed to determine how easily a password hash could be cracked. So, I learned how to use John the Ripper and about hash cracking in general. After concluding that project, I moved onto the next thing. It wasn’t until the next incident a year later that I needed to use John the Ripper again.

Then there are those random questions you never want to waste time figuring out again. Like, “How do I remove newline characters from within quoted text in this csv so that awk sees the quoted text as one field?”

This quick succession and breadth of topics meant that I’d often have to recall something from a few months ago.

So, how do I prevent having to relearn something I knew last week/month/year?

How Tos! lots and lots of How Tos. So many How Tos that managing them became an issue. But that’s a good problem to have, and one I solved with a simple little bash script.

HOWTO.SH

With this script, you can list, search by topic, open, and create new HowTos.

#!/bin/bash

DIRECTORY="$HOME/Documents/HowTo/"

# default (no parameter)
if [ -z "$1" ]; then
  echo 'Key How_To'
# grep excludes README and .DS_Store, all HowTos start with a lowercase tag for the topic
  find $DIRECTORY -type f -maxdepth 1 | awk -F \/\/ '{print $2}' | grep '^[a-z]' | awk '{OFS="\t"}{print $2, $3}' | sort -n
  echo 'Use "help" for more options'
fi

case $1 in
  "list") echo 'Key HowTo' && find $DIRECTORY -type f -maxdepth 1 | awk -F \/\/ '{print $2}' | grep '[0-9]' | awk '{OFS="\t"}{print $2, $3}';; # grep excludes README and .DS_Store, all HowTos start with a lowercase tag for the topic
  "new")
    read -p "What type of HowTo is it? Enter tag:
TAG TOPIC
b Bash Commands. Note: Many have script written, see ~/BashScripts directory
c Code. Things related to code (pulling, commiting, reviewing, etc)
s Servers. (setup, connect, verify, etc.)
t Text. edit, search, etc
m Miscellaneous
" TYPE
    read -p "What would you like to call it?: " ANSWER
    NUMBER=$(($(find $DIRECTORY -type f -maxdepth 1 | awk -F \/\/ '{print $2}' | grep '^[a-z]' | awk '{OFS="\t"}{print $2}' | sort -rn | head -1)+1))
    if [ ! -d "$DIRECTORY" ]; then mkdir $DIRECTORY; fi
    vim $DIRECTORY$TYPE\ $NUMBER\ $ANSWER
    ;;
  "open") open ~/Documents/HowTo && exit;;
  [[:alpha:]]) echo 'Key HowTo' && find $DIRECTORY -type f -maxdepth 1 | awk -F \/\/ '{print $2}' | awk -v pattern="$1" '$1 ~ pattern {print $2, $3}' | awk '{OFS="\t"}{print $1,$2}';; # second awk had trouble with OFS so pipe it into a third awk to format output correctly.
  [[:digit:]] | [[:digit:]][[:digit:]]*) echo 'must enter a two digit key (01 instead of 1 or 001)';;
  [[[:digit:]][[:digit:]]) find ~/Documents/HowTo -type f -maxdepth 1 -name '[a-z]*'$1' *' -exec vim {} \;;;
  "help") echo "Usage: How_To.sh [option]

OPTIONS:
help Show this page
list List all HowTos (default behavior)
new Create a new HowTo
<topic tag> Search HowTos by topic (see TAG below)
<numeric key> Read HowTo associated with key
open Open the HowTo directory

TAG TOPIC
b Bash Commands. Note: Many have script written, see ~/BashScripts directory
c Code. Things related to code (pulling, commiting, reviewing, etc)
s Servers. (setup, connect, verify, etc.)
t Text. edit, search, etc
m Miscellaneous";;
  *) echo "unknown parameter, use help for options. Search by Topic is limited to one tag. Key to read HowTo must be numeric";;
esac

Using the help option will explain what the Topic Tags mean. Then you can make a new HowTo using the new option. Once you’ve written a couple HowTos you’ll be able to find them easily by searching with the Topic Tag, though sometimes I’ll just list them all out and pipe through grep.

It’s made my work much easier having a quick way to parse through my notes and HowTos. Hope it helps you.