Skip to content

Instantly share code, notes, and snippets.

@hatak
Created June 1, 2012 09:01
Show Gist options
  • Save hatak/2850549 to your computer and use it in GitHub Desktop.
Save hatak/2850549 to your computer and use it in GitHub Desktop.
send mail of digest-slowlog
#!/bin/bash
GROUP="hoge-service"
HOST_MASTER="master"
HOST_SLAVE="slave01 slave02 slave03"
MAILTO="[email protected]"
TMPFILE=/tmp/slow-log.`date "+%s"`.log
echo "${GROUP} servers summary" > ${TMPFILE}
echo >> ${TMPFILE}
## master
for TARGET in ${HOST_MASTER}
do
echo "${TARGET} ----------" >> ${TMPFILE}
ssh ${TARGET} "zcat /var/log/mysql/mysqld-slow.log-`date "+%Y%m%d"`.gz" | pt-query-digest >> ${TMPFILE}
echo >> ${TMPFILE}
done
## slave
for TARGET in ${HOST_SLAVE}
do
echo "${TARGET} ----------" >> ${TMPFILE}
ssh ${TARGET} "zcat /var/log/mysql/mysqld-slow.log-`date "+%Y%m%d"`.gz" | pt-query-digest >> ${TMPFILE}
echo >> ${TMPFILE}
done
## mail
cat ${TMPFILE} | mail -s "Summary of slow-query ${GROUP}" ${MAILTO}
rm -f ${TMPFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment