Monthly Archives: September 2013

.bashrc goodies

Here are a couple of goodies I have in my .bashrc to make my life easier. I’ll probably add some more later.

function speed-test {
        # Curls the given address and outputs some nice metrics. Nice for finding where something is slowing things down.
        if [[ $1 ]]; then
                curl -Lw "DNS Lookup: %{time_namelookup} seconds \nRedirects: %{time_redirect} seconds with %{num_redirects} redirects \nFirst Byte: %{time_starttransfer} seconds \nConnect Time: %{time_connect} seconds \nTotal Time: %{time_total} seconds \n" -so /dev/null $1
                echo -e "Usage: $FUNCNAME <url>\nTests and displays HTTP metrics for given URL."

function verify-ssl {
        # Gets information about a given cert. Can be ran against a file, a host, or interactively.
        if [ -z $1 ]; then
                OUTPUT=`openssl x509 -text -noout`
        elif [ -a $1 ]; then
                echo "Found file $1, assuming it's the cert to tested." 
                OUTPUT=`openssl x509 -in $1 -text -noout`
                echo "Assuming input is a hostname. Testing on port 443."
                OUTPUT=`openssl s_client -connect $1:443 </dev/null 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | openssl x509 -text -noout`

        echo "$OUTPUT" | grep "Not Before" -C 2
        echo "$OUTPUT" | grep "Alternative Name" -C 1

# Just echos hodor.
alias hodor='echo hodor'

Happy hacking!