#! /bin/bash # "Divide" a crontab frequency down by the first argument on the command line, # logging to the second argument, and executing the remainder. if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then echo "Usage: $0 frequency logfile command [ arguments ]" >&2 exit 1 fi FREQUENCY="$1" LOGFILE="$2" shift 2 if [ -f "$LOGFILE" ]; then LASTEXEC="$(($(tail -n 1 "$LOGFILE")+1))" else LASTEXEC=1 fi if [ "$LASTEXEC" -ge "$FREQUENCY" ]; then echo "$* executed at $(date)" >> "$LOGFILE" echo 0 >> "$LOGFILE" eval "$*" else echo "$LASTEXEC" >> "$LOGFILE" fi