#!/bin/bash
#
# Quick and dirty database repair script!
#

DAMAGED="`grep "Checking table" /var/log/daemon.log | cut -d "'" -f 2 | uniq`"

for damage in $DAMAGED; do
  db="`dirname $damage | sed -e 's|./||'`"
  tb="`basename $damage`"

  echo "Fixing table $tb on db $db..."
  echo "repair table $tb" | mysql $db
done