Mysql – pt-table-checksum toolkit for few databases from file

MySQLperconapt-table-checksum

I've got a question. I'm doing a simple script right now and it isn't working like I want.

    #!/bin/bash

    cat /etc/backup.conf | egrep -v "(^#.*|^$|^--.*)" > /tmp/databases

    while read line; do
    pt-table-checksum [options] --databases $line --quiet
    done < /tmp/databases

    rm /tmp/databases

As you see I put names of databases to file /tmp/databases. Then I want to use pt-table-checksum for every database in that file line by line. This script works but only for first database name in file. Then it stops.

Any ideas?

Best Answer

I would use a 'for' loop for this, which I have found easier to use for things like this. Often, either line break, spaces, or combinations of those can cause issues with your method. Also, remove the --quiet from your command line to see the errors that pt-table-checksum may be reporting.

#!/bin/bash

for db in `cat /etc/backup.conf | egrep -v "(^#.*|^$|^--.*)"`
do
    pt-table-checksum [options] --databases $db --quiet
done

(Hope this reads ok, have answered on my phone!)