#!/usr/bin/env bash
set -eu
if [ "$#" -ne 1 ]; then
    printf 'Usage: bash count-errors.sh LOG_FILE\n' >&2
    exit 2
fi
if [ ! -f "$1" ] || [ ! -r "$1" ]; then
    printf 'ERROR: cannot read log file: %s\n' "$1" >&2
    exit 1
fi
awk '/ ERROR / { count++ } END { print count+0 }' "$1"
