Check for MySQL databases without existing DirectAdmin users

# Check MySQL databases without existing DA users.
# Be careful, check twice before removing a DB.
for dbuser in ` \
  find /var/lib/mysql \
    -mindepth 1 \
    -maxdepth 1 \
    -type d \
    -exec basename '{}' \; \
    | cut -d'_' -f1 \
    | sort -u \
    | grep -vE "^(da|lost\+found|mysql|performance)\$"`; \
do \
  if ! ls -1 /usr/local/directadmin/data/users/ \
    | grep -qE "^$dbuser\$"; \
  then \
    echo "Check: ${dbuser}_* database(s)"; \
  fi; \
done;

Leave a Reply

Your email address will not be published. Required fields are marked *