Check Drupal Module Status Using Bash

When you run a lot of drupal sites it can be annoying to keep track of all of the modules contained in a platform and ensure all of them are up to date. One option is to setup a dummy site setup with all the modules installed and email notifications enabled, this is OK, but then you need to make sure you enable the additional modules every time you add something to your platform.

I wanted to be able to check the status of all of the modules in a given platform using the command line. I started scratching the itch by writing a simple shell script to use the drupal updates server to check for the status of all the modules. I kept on polishing it until I was happy with it, there are some bits of which are a little bit ugly, but that is mostly due to the limitations of bash. If I had to rewrite the it I would do it in PHP or some other language which understands arrays/lists and has http client and xml libraries.

The script supports excluding modules by using a extended grep regular expression pattern and nominating a major version of drupal. When there is a version mismatch it will be shown in bolded red, while modules where the versions match will be shown in green. The script filters out all dev and alpha releases, after all the script is designed for checking production sites. Adding support for per module update servers should be pretty easy to do, but I don't have modules to test this with.

To use the script, download it, save it somewhere handy, such as

, make it executable (run
chmod +x ~/bin/
). Now it is ready for you to run it -
~/bin/ /path/to/drupal
and wait for the output.

#!/bin/bash # # Check the latest version of a drupal module / template # # Written by Dave Hall # Copyright (c) 2010 Dave Hall Consulting # Licensed under the terms of the GPLv3 # BASE_URL='' if [[ 0 -eq $# || 3 -lt $# ]]; then echo Usage: $(basename $0) /path/to/drupal-instance [[exclude-pattern] drupal-version] exit 1 fi DRUPAL_PATH=$1 if [ ! -d "$DRUPAL_PATH" ]; then echo ERROR: Invalid path - $DRUPAL_PATH exit 2 fi EXCLUDE_PATTERN='(drupal)' if [ 2 -lt $# ]; then EXCLUDE_PATTERN=$2 fi DRUPAL_VERSION=6.x if [ 3 -eq $# ]; then DRUPAL_VERSION=$3 fi INFO_FILES=$(find $DRUPAL_PATH -name *.info) modules=( ) for info in $INFO_FILES; do project=$(sed -e '/project =/!d' -e 's/project = "\(.*\)"/\1/g' < $info | head -n1) if [[ "" == "$project" || 0 -eq $(echo $project | egrep -cv $EXCLUDE_PATTERN) ]]; then continue fi cur_ver=$(sed -e '/version =/!d' -e 's/version = "\(.*\)"/\1/g' < $info | tail -n1) modules=( "${modules[@]}" "$project|$cur_ver##" ) done modules=$(echo ${modules[@]} | tr '##' '\n' | sort -u) echo -e "module\t\tlocal\tcurrent" for mod in $modules; do color='\e[0;32m' new_ver=$(wget -O -`echo $mod | cut -d\| -f1`/$DRUPAL_VERSION 2> /dev/null | sed -e '/<version>.*<\/version>/!d' -e '/\(dev\|alpha\)/d' -e 's/.*<version>\(.*\)<\/version>/\1/g' | head -n1 ); if [ "$(echo $mod | cut -d\| -f2)" != "$new_ver" ]; then color='\e[1;31m' fi echo -e $color$mod\|$new_ver | tr '|' '\t' done
check-module-status.sh1.59 KB

You might find Drush

Lindsay Holmwood wrote:

You might find Drush interesting.

Added Mon, 2010-02-22 04:35

RE: You might find Drush

Dave wrote:

Drush is great, but last I looked it only checks the status of enabled modules in a site. I wanted to avoid having a dummy site with all the modules enabled just for tracking if modules are up to date.

Added Mon, 2010-02-22 09:31

core updater

Vyacheslav Trotsak wrote:

I prefer core updater (Drupal 6). Very useful option.

Added Thu, 2010-05-06 01:32

Drupal Script Library

Anonymous wrote:

I have written an extensive set of bash scripts for managing sets of Drupal sites. Among the scripts, there's one called '' that will generate a report like this:

[[email protected] ~]$ status Site: Install dir: /home/toddgee/webroot/drupal/ Drupal version: 6.17-dev* (tag DRUPAL-6/latest tag:DRUPAL-6-16) Installed non-Contrib Modules: format: : {modules active from that installation} Installed Contrib Modules: format: [*] (/[]): {modules active from that installation} admin_menu (tag DRUPAL-6--3): admin_menu adminblock (tag DRUPAL-6--1): adminblock advanced_help (branch DRUPAL-6--1-2): advanced_help better_formats* (tag DRUPAL-6--1/DRUPAL-6--2): better_formats fckeditor* (tag DRUPAL-6--2): fckeditor Installed library file: FCKeditor_2.6.6.tar.gz google_analytics (tag DRUPAL-6--2): googleanalytics path_redirect (tag DRUPAL-6--1): path_redirect pathauto* (tag DRUPAL-6--1/DRUPAL-6--2): pathauto private (tag DRUPAL-6--1): private tableofcontents* (tag DRUPAL-6--3): tableofcontents taxonomy_navigator (tag DRUPAL-6--1): taxonomy_navigator token* (tag DRUPAL-6--1): token ('' indicates CVS updates available for item)

[[email protected] ~]$

The starts mean that there are pending updates.


Added Fri, 2010-05-07 03:05

RE: Drupal Script Library

Dave wrote:

I didn't dig too deep into it, but it looks quite comprehensive. One question, why not just use drush? I plan to port my code to drush when I get some time.

Added Fri, 2010-05-07 11:08

I think you are looking for

david wrote:

I think you are looking for drush pm-releases

Added Wed, 2010-08-04 12:58

RE: I think you are looking for

Dave wrote:

As I understand it drush pm-releases relies on an installed site. I hope to have something that will just provide status information for all modules in a (sub) directory.

Added Wed, 2010-08-04 14:33

Script Does not work!

Anonymous wrote:

The concept is exactly what I need, but I cannot get it to work. I cannot download the script, it gives me a 404. I used the script you have up here... did a copy paste, format, chmod +x then ran it and got a list of the contents of my modules folder with nothing relative. Below is three lines of what I got

28 drupal/drupal6/modules/path 104 drupal/drupal6/modules/book 356 drupal/drupal6/modules/system

Please help

Added Fri, 2011-07-08 08:16