Shell script:

Digital and Physical Security Consulting and Training

Template for a basic shell script. This provides a sample of logging from a shell script.

#! /bin/sh
## 2012-11-07 Vik Solem
## template for shell scripts

MYname=`basename $0`
LOGDIR="${ROOT}logs/`date +'%Y-%m'`/"
DATADIR="${ROOT}data/`date +'%Y-%m'`/"
NOW=`date +'%Y-%m-%d_%H-%M-%S'`
mkdir -p ${ROOT}
mkdir -p ${LOGDIR}
mkdir -p ${DATADIR}

log() {
    echo `date +'%Y-%m-%d_%H-%M-%S'`" $*" | tee -a ${LOGFILE}
cmd() {
    log "$*"
    $* 2>&1 | tee -a ${LOGFILE}
skip() {
    log "SKIPPING this command: $*"
log Start

cmd ls
skip cmd rm file-to-delete

log Finish