Last active
August 29, 2015 14:05
-
-
Save davedash/1a408486cae6a129584f to your computer and use it in GitHub Desktop.
This file contains 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 | |
CHUNK=5 | |
MYSQL_CMD="SHOW SLAVE STATUS\G" | |
MYSQL="/usr/bin/mysql" | |
GREP="grep Sec" | |
START=$(echo $MYSQL_CMD|$MYSQL|$GREP|cut -d: -f2) | |
i=0 | |
function slaving_stopped { | |
if [[ "$1" -eq "NULL" ]]; then | |
echo "Slaving stopped!" | |
exit 1; | |
fi | |
} | |
slaving_stopped $START | |
while true; do | |
(( i += 1 )) | |
sleep $CHUNK | |
END=$(echo $MYSQL_CMD|$MYSQL|$GREP|cut -d: -f2) | |
slaving_stopped $END | |
TIME_IN_CHUNK=$(expr $START - $END) | |
MINS=$(expr $END / $TIME_IN_CHUNK \* $CHUNK \* $i / 60) | |
if [[ $MINS -lt 90 ]]; then | |
REM="$MINS minutes" | |
else | |
(( HOURS= $MINS / 60 )) | |
REM="${HOURS} hours" | |
fi | |
echo "$END seconds remaining. Should take $REM." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment