#!/bin/bash
#------------------------------------------------------------------------------
set -u
# Usage:
# Login as EDITME_USER@EDITME_HOST
# cd /dir/where/this/runs/EDITME
# nohup ./sample_nohup_wrapper.sh < /dev/null > sample_nohup_wrapper.$(date +'%Y%m%d-%H%M').log 2>&1 &
# EDITME: Replace sample_nohup_wrapper with you actual script name in the
# comment above. Keep this comment accurate, and in the top 10 lines of the
# script so that you can do 'head sample_nohup_wrapper.sh' and be able to
# copy/paste the nohup command directly.
function msg () { echo -e "$*"; }
function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit ${2:-1}; }
declare Version=1.0.1
declare ThisThat="OrTheOther"
# Define shell environment settings here.
ThisHost=$(hostname -s)
msg "Started ${0##*/} v$Version on $ThisHost at $(date)."
# EDITME - Repeat this next block for each command you want to run.
Cmd="ls -lrt /tmp"
msg "Executing: $Cmd"
$Cmd || bail "Failed to EDITME."
msg "That took $(($SECONDS/3600)) hours $(($SECONDS%3600/60)) minutes $(($SECONDS%60)) seconds.\n"