Skip to main content
deleted 51 characters in body
Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96
#!/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

#!/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)

it's skip last record , I don't know why

#!/usr/bin/env bash

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' /var/log/secure)

it's skip last record , I don't know why

Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96

#!/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)

it's skip last record , I don't know why