#! /bin/bash . /usr/src/m2/framework/bash_functions.sh DB_PASSWORD=`cat /etc/m2/system.conf | grep dbsecret | awk '{print $3}'` DB_USERNAME=`cat /etc/m2/system.conf | grep dbuser | awk '{print $3}'` DB_NAME=`cat /etc/m2/system.conf | grep dbname | awk '{print $3}'` DB_HOST=`cat /etc/m2/system.conf | grep dbhost | awk '{print $3}'` rm -fr /tmp/m2_temporary_tables.txt mysql --skip-column-names -h $DB_HOST $DB_NAME -u $DB_USERNAME -p$DB_PASSWORD -e "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'm2' AND table_name REGEXP 'import_.*_[0-9]+' AND create_time < (NOW() - INTERVAL 1 DAY)" > /tmp/m2_temporary_tables.txt TABLE_COUNT=`cat /tmp/m2_temporary_tables.txt | grep -Po "import_.*_[0-9]+" | wc -l` if [ "$TABLE_COUNT" != "0" ]; then report "Following temporary tables should be deleted:" 2 echo "" cat /tmp/m2_temporary_tables.txt | grep -Po "import_.*_[0-9]+" echo "" for i in `cat /tmp/m2_temporary_tables.txt | grep -Po "import_.*_[0-9]+"`; do echo "Removing table: $i" mysql -h $DB_HOST $DB_NAME -u $DB_USERNAME -p$DB_PASSWORD -e "DROP TABLE IF EXISTS $i" done fi rm -fr /tmp/m2_temporary_tables.txt