X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=blobdiff_plain;f=crondiv;h=1157511fb26217f35d2792ecc6378837006ce8a0;hp=666171c6bafce1ded23419475a5674895b0dad21;hb=aad995cb81c811011cfbda01c5cc46591842aaca;hpb=88c7e302a60194f68bc1b6d20c1547b62e1436d3 diff --git a/crondiv b/crondiv old mode 100644 new mode 100755 index 666171c..1157511 --- a/crondiv +++ b/crondiv @@ -3,26 +3,26 @@ # "Divide" a crontab frequency down by the first argument on the command line, # logging to the second argument, and executing the remainder. -if [ "X$1" = "X" -o "X$2" = "X" -o "X$3" = "X" ]; then +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then echo "Usage: $0 frequency logfile command [ arguments ]" >&2 exit 1 fi -FREQUENCY=$1 -LOGFILE=$2 +FREQUENCY="$1" +LOGFILE="$2" shift 2 -if [ -f $LOGFILE ]; then - LASTEXEC=$(($(tail -n 1 $LOGFILE)+1)) +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 +if [ "$LASTEXEC" -ge "$FREQUENCY" ]; then + echo "$* executed at $(date)" >> "$LOGFILE" + echo 0 >> "$LOGFILE" eval "$*" else - echo $LASTEXEC >> $LOGFILE + echo "$LASTEXEC" >> "$LOGFILE" fi