From a3f5343ab6d2596bb8323e0fad3d9bef207295b7 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Jun 23 2020 15:12:36 +0000 Subject: countme-update-*.sh: exit correctly on unrecognized option Make these scripts exit with an error message (containing the correct program name) if you you pass unknown options. --- diff --git a/countme-update-rawdb.sh b/countme-update-rawdb.sh index 735054f..ccf1501 100755 --- a/countme-update-rawdb.sh +++ b/countme-update-rawdb.sh @@ -78,13 +78,16 @@ rawdb_lastlog_date() { ### Here's the CLI options and CLI parsing stuff. ### +# Basename of the script +PROGNAME="${0##*/}" + # die msg... # print msg to stderr and exit. -die() { echo "${0##*/}: $@" >&2; exit 2; } +die() { echo "$PROGNAME: $@" >&2; exit 2; } usage() { cat <<__USAGE__ -usage: ${0##*/} [OPTIONS..] +usage: $PROGNAME [OPTIONS..] Find "countme=N" items in daily httpd logs and put them in a SQLite database. If the database exists, starts from the day after the last database item. @@ -120,10 +123,11 @@ VERBOSE="" PROGRESS="" PARSECMD_ARGS=() -options=$(getopt -o hvn \ +options=$(getopt --name "$PROGNAME" \ + --options hvn \ --long help,verbose,dryrun,progress,logdir:,logfmt:,rawdb:,all,start: \ -- "$@" \ -) +) || exit 1 eval set -- "$options" while true; do diff --git a/countme-update-totals.sh b/countme-update-totals.sh index 4d493aa..400ce62 100755 --- a/countme-update-totals.sh +++ b/countme-update-totals.sh @@ -19,14 +19,16 @@ DEFAULT_TOTALSCSV="$OUTPUT_DIR/countme-totals.csv" ### Option defaults and CLI parsing code ### +# Basename of the script +PROGNAME="${0##*/}" # die msg... # print msg to stderr and exit. -die() { echo "${0##*/}: $@" >&2; exit 2; } +die() { echo "$PROGNAME: $@" >&2; exit 2; } usage() { cat <<__USAGE__ -usage: ${0##*/} [OPTIONS..] +usage: $PROGNAME [OPTIONS..] Read "countme-raw" database, count hits, and write SQLite + CSV output. Only writes data for complete weeks that are not in the output database. See '$COUNTCMD' for more details. @@ -53,10 +55,11 @@ PROGRESS="" DRYRUN="" COUNTCMD_ARGS=() -options=$(getopt -o hn \ +options=$(getopt --name "$PROGNAME" \ + --options hn \ --long help,dryrun,progress,rawdb:,totals-db:,totals-csv: \ -- "$@" \ -) +) || exit 1 eval set -- "$options" while true; do