Created
September 23, 2014 21:20
-
-
Save entrity/a39e014d25979d832e21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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