I am trying to configure a script where a warning appears when a specific line appears in the log file.
The solution that is already in use clears the entire log file daily and counts how often the line appears, using the timestamp of the log line to only count the occurrences in the previous minute.
I thought it would be much more efficient to do this with the tail, so as a test I tried the following:
FILENAME="/var/log/file.log"
tail -f $FILENAME | awk -F , -v var="$HOSTNAME" '
BEGIN {
failed_count=0;
}
/account failure reason/ {
failed_count++;
}
END {
printf("%saccount failure reason (Errors per Interval)=%d\n", var, failed_count);
}
'
but it just freezes and outputs nothing. Someone suggested this minor change:
FILENAME="/var/log/file.log"
awk -F , -v var="$HOSTNAME" '
BEGIN {
failed_count=0;
}
/account failure reason/ {
failed_count++;
}
END {
printf("%saccount failure reason (Errors per Interval)=%d\n", var, failed_count);
}
' <(tail -f $FILENAME)
but it does the same thing.
It uses awk, which I use (I am simplified in the code above), since it is used in an existing script, where grep "^ $ TIMESTAMP" results are passed to it.
: -f awk?