Listing Enabled Modules Using a bash Script

Category
Drupal Version
Tags

A shell script that prints out a list of enabled modules in all accessible databases, designed for ssh use when you need to check multiple Drupal 6 or 7 databases at one time.

Editor's Note:  A similar concept would work just as well for Drupal 8, but the database table names and structures have changed in Drupal 8, so you would need to adjust the script accordingly.  Also, be aware that this script will not work on any Drupal instance where you have used a custom table prefix for all of your Drupal site tables.

With thanks to Abdul Manaf on DBA.stackexchange for the basic code.


# mysql credential
user="root"
pass="pwd"

all_dbs="$(mysql -u $user -p$pass -Bse 'show databases')"        

# Exclude databases you don't want to check, such as non-Drupal 6 or 7 dbs.
# Then output database name and an alphabetized list of Enabled modules.
for db in $all_dbs
     do
        if [[ "$db" != "information_schema" &&
            "$db" != "mysql" &&
            "$db" != "performance_schema" &&
            "$db" != "test" ]] ; then
            echo '====================='
            echo "DATABASE: $db (ENABLED Modules)"
            echo "---------------------------"
            mysql -u$user -p$pass $db -sN -e "SELECT name FROM system WHERE status = 1 AND type = 'module' ORDER BY name ASC;" 
        fi 
     done