Scan a file in realtime and execute certain commands on encountering 5 consecutive identical lines

Mysql log has something like below:

I need a bash shell script that will do the following:

1) The script will scan the mysql.log file constantly in real time (something like tail -F mysql.log)
2) If it encounters 5 consecutive identical lines then it would invoke some commands (say echo "yes")

Please help.

This appears to be a continuation of:
http://www.unix.com/shell-programming-scripting/176523-how-grep-portion-line.html?ign=advisor&ignP=302596963

What does "tail -F" do on your Operating System? Not valid on mine. What Operating System and version do you have?

In general it is a major programming exercise to "tail -f" a file and carry out any further processing in a pipeline. There have been posts on this board which suggest using named pipes.

tail -F is same as tail -f --retry

man tail
       --retry
              keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later; useful when  following  by  name,  i.e., with --follow=name

Available on GNU/Linux

If you are using GNU/Linux checkout fflush() in gawk:

tail -F infile | awk 'function ff(){ if(A[p]>4) {print "yes - " p; fflush() ; A[p]=0 } } {ff(); A[$0]++} $0!=p{p=$0} END{ff()}'

*edit* Actually, this should suffice, since the END section will never happen:

tail -f infile | awk 'A[p]>4{print "yes - " p; fflush(); A[p]=0} $0!=p{p=$0} {A[p]++}'

What about: