Days between two dates

This little script reports back how many days fall between two arbitrary dates, or one date and today. If you put in a date in the future, it tells how many days as a negative;

# How many days 'till Christmas?
HowManyDays 2017-12-25
-115



#!/bin/bash
# SRJ 2017-08-31
date1=$(date --utc --date "${1}" +%s)
Ex=$?
# The line above puts the exit status of the date command
# into the Ex variable, the lines below exit the shell if
# there was an error reported.
if [ ! ${Ex} = 0 ]
then
exit 1
fi

if [ -z "${2}" ]
then
date2=$(date --utc +%s)
else
date2=$(date --utc --date "${2}" +%s)
Ex=$?
# The line above puts the exit status of the date command
# into the Ex variable, the lines below exit the shell if
# there was an error reported.
if [ ! ${Ex} = 0 ]
then
exit 1
fi
fi

diffdays=$(( (date2-date1)/(3600*24) ))

if [ ${diffdays} = 0 ]
then
echo This script requires a valid date in the form yyyy-mm-dd or, for
echo example, HowManyDays 2015-09-23 will report the number of days
echo that have passed between 2015-09-23 and today.
echo
echo If this script is given two dates, it returns the number of days
echo between those two dates, if the second date is earlier than the
echo first, the result will be a negative number.
echo HowManyDays 2015-09-23 2016-02-27 will return 157.
exit 1
fi

echo ${diffdays}

TinyPad

#!/bin/bash
#      SRJ 2016-09-20 Create reasonable passwords
# This is ~/bin/TinyPad
# This script produces 26 rows of 3 columns of 13 characters each.
# It was written to create ISO-ID-1 Cards to carry in the wallet, with 
# a letter before each row as a reminder (I use row G for Google passwords
# for example.
 
Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.!@#$%&-_=+abcdefghijklmnopqrstuvwxyz"
Count=${#Chars}   # Length of $Chars
# You can remove specific characters to avoid ambiguity, O or 0 for instance,
# though, if you print this in Courier, the symbols are quite unique.
 
Ran()
{
# This function generates a random number, returns the modulus of that number 
# in the range of 1 to (Number of characters in $Char), and then returns the 
# single character from $Char at that position
Offset=$(($(head -c4 /dev/urandom | od -N2 -tu2 | sed -ne '1s/.* //p')%$Count))
echo "${Chars:${Offset}:1}"
};
 
for Row in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
do echo -n "${Row} "
  for Column in 1 2 3
  do for Char in 1 2 3 4 5 6 7 8 9 10 11 12 13
    do echo -n "$(Ran)"
    done  ; echo -n " "
  done ; echo ""
done
# The 3 embedded loops above spit out the Rows, Columns, and Char to form an
# array that is designed to fit on a credit card for your wallet. 
 
# For the line below to work properly, you have to install the enscript package,
# then add a media definition in the form;
# Media:	Card		242	153	5	9	228	145 
# to the /etc/enscript.cfg file
# TinyPad | enscript -BM Card --margins=10:9 --output=- -f CourierBold8/9 | ps2pdf - Pad.pdf
# Produces a file, Pad.pdf that can be printed directly with the card printer 
# at the front desk.

Pad.pdf

Perfect_Printers

I wrote this a loong time ago, it amuses me to see that it still seems to work.
The comments in this one make it pretty self-explanatory;

#!/bin/sh
# This gives a list of only the perfectly supported printers under Linux
# It makes a nice list to take with you when you're going to the store.
# 
# The current list of printers include these manufacterers;
# Alps Anitech Apollo Apple Avery Brother CalComp Canon Casio Citizen 
# CItoh Compaq DEC Dell Dym Epson Fuj Fujifilm Fujitsu Generic Genicom
# Gestetner Heidelberg Hitachi HP IBM Imagen Imagistics InfoPrint 
# Infotec Kodak KONIC Kyocera Lanier LaserMaster Lexmark Minolta 
# Mitsubishi NEC NFCP NRG Oce Oki Olivetti Olympus Panasonic PCPI 
# Pentax Pixma Printrex QMS Raven Ricoh Samsung Savin Seiko Sharp 
# SiPix Sony Star Tally TallyGenicom Tektronix Toshiba Tysso Xante 
# Xerox
# 
# Edit the line below to include the printer manufacturers that you have
# an interest in, then run this script.
 
Manufacturers="Brother Epson HP"
 
for Each in $Manufacturers 
 do
  echo "=-=-=-=- $Each -=-=-=-="
  elinks -no-numbering -dump 1 http://www.openprinting.org/printers/manufacturer/$Each \
  | sed -e '1,/Perfect/d' -e '/Mostly/,$d' -e '/^$/d'
 done

Bash_Boggle

I wrote this little script one evening a long time ago, for someone who wanted to take pre-printed sheets to work, as it was more stimulating than the work…

#!/bin/bash
# Print out a Boggle board to stdout.
# The 16 dice and their 6 sides each, this creates Dice[n]=
Dice=\
(QBAJOM EFIEYH ODENWS HPSEIN GKYLUE ILUWRG CITAOA BYLTIA \
 DZNVEA ODUNKT RHASOM PAECMD GVZTEI OFIRXB REALSC PELUTS)
#
AllDice="  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15"

# Cut the string that represents the order of the dice in 
# the tray 99 time at some random point, then swap the parts
# around. Repeat as needed.
for ((a=1; a <= 100 ; a++))
do
   LeftCut=$(($(($(($RANDOM%15))*3))+3))
   RightCut=$((LeftCut+3))
   LeftEnd=${AllDice:0:LeftCut} 
   RightEnd=${AllDice:RightCut}
   Middle=${AllDice:LeftCut:3}
   AllDice="$Middle$LeftEnd$RightEnd"
done
# Roll the Dice to get what side is up.
Count=0
for Each in $AllDice
    do
    Side=$(($RANDOM%6))
    Die=${Dice[Each]:Side:1}
    [ $Die == Q ] && echo -n $Die"u " || echo -n $Die"  "
    [ $((Count%4)) -eq 3 ] && echo
    (( Count++ ))
    done

Pad

This generates a list of passwords, as a pad, I carry a subset of one of these with me in case I need a truly random password while I’m out.

#!/bin/bash
#      SRJ 2016-09-20 Create reasonable passwords
#      0        1         2         3         4         5         6         7
#      1234567890123456789012345678901234567890123456789012345678901234567890123456789
Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.!@#$%&-_=+abcdefghijklmnopqrstuvwxyz"
# The column labels are taken from the beginning of the $Chars string
Count=${#Chars}   # Length of $Chars
R="60"   # Number of rows in output, 60 works well
C="6"   # Number of columns in output, 6 is the way
L="12"  # Length of string, 12 is ideal
# Shouldn't need to change anything below here
 
if [ ! -z ${1} ] ; then R="${1}" ; fi
if [ ! -z ${2} ] ; then C="${2}" ; fi
if [ ! -z ${3} ] ; then L="${3}" ; fi
 
d=$((L/2)) ; ((d++)) # Half of L plus 1
Sep="-"   # The Seperator at the top of each column
Blanks="" # This line and next generate the empty space at the beginning of each line
for z in $(seq 1 ${#R}) ; do Blanks+=" " ; done
 
Ran()
{
Offset=$(($(head -c4 /dev/urandom | od -N2 -tu2 | sed -ne '1s/.* //p')%$Count))
echo "${Chars:${Offset}:1}"
};
 
# Generate the top two lines of the report, labeling the columns and adding
# a seperator line
for Row in $(seq -w 0 1)
do echo -n "${Blanks}| "
  for Column in $(seq -w 1 ${C})
  do for Place in $(seq -w 1 ${L})
    do if [ ${Row} = "1" ] ; then
      echo -n "${Sep}"
      else if [ ${Place} -eq ${d} ] ; then
        echo -n ${Chars:$((Column-1)):1}
        else echo -n " " ; fi ; fi
    done ; if [ ! ${Column} -eq ${C} ] ; then echo -n " " ; fi
  done ; echo ""
done
 
# Send out the rows and columns of random characters
for Row in $(seq -w 1 ${R})
do echo -n "${Row}| "
  for Column in $(seq -w 1 ${C})
  do for Place in $(seq -w 1 ${L})
    do echo -n "$(Ran)"
    done ; if [ ! ${Column} -eq ${C} ] ; then echo -n " " ; fi
  done ; echo ""
done