Skip to content

Instantly share code, notes, and snippets.

@xxorax
Created June 3, 2016 10:49
Show Gist options
  • Save xxorax/d8d1c612cf6a011120e4be96e1600b9c to your computer and use it in GitHub Desktop.
Save xxorax/d8d1c612cf6a011120e4be96e1600b9c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author: Martin PANEL
# Description: find all crashed mysql table from a log file, a run request to repair them
# Usage : mysqlRepairTableFromLog.sh [logFile]
# logFile: file log or /var/log/syslog by default
#
# env var $MYSQL_OPTS can be used to add mysql params
#
log=/var/log/syslog
if [ ! -z "$1" ]; then
log="$1"
fi
tables="$(grep -i crashed "$log" | grep -i mysql | sed -r 's/.*Table ...(.+). is marked .+/\1/' | sort -u)"
request="repair table $(echo "$tables" | tr '\/\n' '.,' | sed 's/.$//');"
echo "$request" | mysql $MYSQL_OPTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment