HEX
Server: CentOS WebPanel: Protected by Mod Security
System: Linux sites.annaiservers.com 3.10.0-1160.118.1.el7.x86_64 #1 SMP Wed Apr 24 16:01:50 UTC 2024 x86_64
User: freeval (1012)
PHP: 8.1.10
Disabled: NONE
Upload Files
File: //scripts/checkdb
#!/bin/bash
# CWPscripts: Check for bad tables

# Configuration
logfilelocation="/var/log/mysqlcheck.log"

# Remove old log file
rm -f $logfilelocation

# Scan all tables
for database in `mysql -e "show databases;" -B --skip-column-names |grep -v "information_schema\|performance_schema"`;do
    for table in `mysql $database -e "show tables;" -B --skip-column-names`;do
        #mysqlcheck $database $table |grep -v "OK" 2>&1 >> /root/mysqlcheck.txt
        checktable=`mysqlcheck $database $table | grep -v "OK" 2>&1`

        if [ ! -z "$checktable" ];then
            echo "|DATABASE: $database| |TABLE: $table| ERROR: $checktable" >> $logfilelocation
        fi
    done
done

# Send alert in CWP
if [ -e "/scripts/add_alert" ];then
    if [ -e "$logfilelocation" ];then
        sh /scripts/add_alert alert-danger "Bad or Corrupted MySQL Databases/Tables detected!" $logfilelocation
    fi
fi