#!/bin/bash

# mysqlcheck2
# (C) 2012 Daniel Marschall, ViaThinkSoft
# Version 1.0

# Example: ./mysqlcheck2 -Ae

# This script invokes mysqlcheck, but strips all "OK" lines as well as the following ("non errors"):
# Error    : You can't use locks with log tables.
# note     : The storage engine for the table doesn't support check

hold="";
prevremove=1;
(
	mysqlcheck $* | grep -v "OK"
	status=$?;
	echo ""	# Damit das letzte "hold" ausgegeben wird.
	exit $status;
) | while read inputline ;
do
	echo "$inputline" | grep "You can't use locks with log tables." > /dev/null ;
	if [[ $? -eq 0 ]];
	then
		remove=1;
	else
		echo "$inputline" | grep "The storage engine for the table doesn't support check" > /dev/null ;
		if [[ $? -eq 0 ]];
		then
			remove=1;
		else
			remove=0;
		fi
	fi

	if [[ $remove -eq 0 ]];
	then
		if [[ $prevremove -eq 0 ]];
		then
			echo "$hold";
		fi
		hold="$inputline";
	else
		hold="";
	fi

	prevremove=$remove;
done

exit ${PIPESTATUS[0]};
