Skip to content

Instantly share code, notes, and snippets.

@entrity
Created September 23, 2014 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save entrity/a39e014d25979d832e21 to your computer and use it in GitHub Desktop.
Save entrity/a39e014d25979d832e21 to your computer and use it in GitHub Desktop.
#!/bin/bash
pattern=$1
mtime=$2
grep_args="-q -i"
[[ ! -z "$3" ]] && grep_args=$3
export pattern
count=0
export count
# args are <filename>
search () {
count=$(($count+1))
printf "\033[s\033[0;0H\033[K%9d\033[u" $count
# Echo filename if it contains a match
mysqlbinlog $1 | grep $grep_pargs "$pattern" && echo ===$1===
}
export -f search
if [ -z "$1" ] || [ -z "$2" ]; then
echo Usage:
echo "./search_mysql_logs.sh <pattern> <days> [options]"
echo -e "\t where <days> is the max number of days ago to search"
exit 1
fi
find /var/lib/mysql -name "mysql-bin.*" -mtime -$mtime -exec /bin/bash -c "search {}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment