bash strict mode
(I generally don’t set the IFS as recomended)
set -e #exit immediately if a simple command exits with a non-zero status
set -u #treat unset variables as an error when performing parameter expansion
set -o pipefail #exit status of last non-zero exit code is returned
create temp file
tempfile="$(/bin/mktemp)"
script name
strips of everything before the last “/”
scriptname="${0##*/}"
hostname
#find our current host
fqdn="$(/bin/hostname)"
#strip off everything after the first "."
host="${fqdn%%.*}"
date time
datetime="$(/bin/date "+%Y%m%dT%H%M%S")"
test its a number
Useful for checking a number was passed from the cli
re='^[0-9]+$'
if ! [[ ${1} =~ $re ]] ; then
echo "error: $0 NUMBER" >&2; exit 1
fi