Hello!
I've got script to write. It should read databases (names, volumes) from table testdatabase and compares it to actually existing databases in /var/lib/mysql/. If there is no informations about database in table - we should see information "There is no declared informations about database in table testdatabase." And if volume of database is too big - we should see information "Database database has too big actual size volume, it exceeds declared size in table testdatabase."
My problem is that even if there is existing database in /var/lib/mysql/ and I put informations about it in table testdatabase - I see statement - "There is no declared...".
Do you have any idea what am I doing wrong?
cd /var/lib/mysql/ || exit 1
gawk '
BEGIN {
cmd = "mysql -u root -ppassword knowdatabases \"SELECT name, volume, date, description FROM testdatabase\""
while ( cmd | getline ) {
DATABASE[$1,1] = $2;
DATABASE[$1,2] = $1;
}
close(cmd)
cmd = "find /var/lib/mysql/ -maxdepth 1 -mindepth 1 -type d | xargs du -sm"
while ( cmd | getline ) {
VOL = $1;
NAM = $2;
if ( ! DATABASE[NAM,1] ) {
print "There is no declared informations about " NAM " in table testdatabase."
continue
}
if ( VOL > DATABASE[NAM,1] ) {
print "Database " NAM " has too big actual size (" VOL "), it exceeds declared size in table testdatabase."
continue
}
}
close(cmd)
}
' /dev/null