#!/usr/bin/env bash
[[ $# -eq 0 ]] && { echo "Error: Specify inputfile" >&2; exit; }
c=1
while read line
do
a=( $line )
d="${a[@]::3}"
logdate=$( date '+%F' -d"$d" )
if [[ $logdate == $old_logdate ]]; then
(( c++ ))
elif [[ $old_logdate != $logdate ]]; then
printf "%s\t%s\t%s%s\n" "Date: $old_logdate Number of failed attempts: $c"
old_logdate=$logdate
c=1
continue
else
printf "%s\t%s\t%s%s\n" "Date: $logdate Number of failed attempts: $c"
fi
done < <(grep 'authentication failure' $1/var/log/secure)
it's skip last record , I don't know why