Rob Scripts

Rob writes bash scripts.

Random, memorable-ish password generator

June 12, 2015 — Rob Hutten

For when you need a new password or twelve. Not all /usr/dict/words files are created equally; I encourage finding/generating your own dictionary of short words.

#!/bin/bash
#
# Rob Hutten 2015
# http://hutten.org/rob/scripts/
# Generate some semi-not-horrible passwords
# Requires a 'sort' with the -R option.

function ranDigit() {
        echo $RANDOM | rev | cut -c1
}

function makeOne() {
        ( grep ^....$ $dict | sort -R | head -1 | sed "s/./\U&/"
          grep ^....$ $dict | sort -R | head -1
          ranDigit
          echo '; : . , = + -' | tr ' ' '\012' | sort -R | head -1
        ) | sort -R | tr -d '\012'
        echo
}

#-- main
PATH=/bin:/usr/bin
dict=/usr/share/dict/words

if [ $# -gt 0 ] ; then
        for i in $(seq 1 $1) ; do
                makeOne
        done
else
        makeOne
fi

Tags: passwords

Replace IPs in stdin with their DNS names

June 12, 2015 — Rob Hutten

This script takes standard input and replaces any occurance of an IP address with its name as per a DNS lookup.

#!/bin/bash
#
# Rob Hutten, 2015
# http://hutten.org/rob/scripts
# Reads from stdin; replaces IP addresses with their names
# as found in the DNS.

PATH=/bin:/usr/bin
sedscript=$(mktemp /tmp/poot.XXXXX)
input=$(mktemp /tmp/toot.XXXXX)

cat > $input

ips=($(tr ' ,:' '\012\012\012' < $input \
	| egrep '^[0-9\.][0-9\.]*$' \
	| egrep '[0-9]' \
	| egrep '\.' \
	| sort | uniq))

cat > $sedscript << EOF
#!/usr/bin/sed -f
EOF

for ip in ${ips[@]} ; do
        dns=$(host $ip | rev | awk '{print $1}' | rev | cut -d\. -f1)
        if [[ $dns =~ SERVFAIL ]] ; then
                dns=$ip
        fi
        echo s/${ip}/${dns}/g >> $sedscript
done

chmod +x $sedscript

$sedscript < $input
rm -f $sedscript $input

Tags: bash, dns, IP

New blog

June 12, 2015 — Rob Hutten

There aren't nearly enough mediocre bash scripting blogs out there. Here's one more.