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
~/bin/check-module-status.sh, make it executable (run
chmod +x ~/bin/check-module-status.sh). Now it is ready for you to run it -
~/bin/check-module-status.sh /path/to/drupaland wait for the output.
#!/bin/bash
#
# Check the latest version of a drupal module / template
#
# Written by Dave Hall http://davehall.com.au
# Copyright (c) 2010 Dave Hall Consulting http://davehall.com.au
# Licensed under the terms of the GPLv3 http://www.gnu.org/licenses/gpl.html
#
BASE_URL='http://updates.drupal.org/release-history/'
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 - http://updates.drupal.org/release-history/`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
| Attachment | Size |
|---|---|
| check-module-status.sh | 1.59 KB |

RSS Feed
You might find Drush
Lindsay Holmwood wrote:You might find Drush interesting.
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.
core updater
Vyacheslav Trotsak wrote:I prefer core updater (Drupal 6). Very useful option.
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 'drupalReport.sh' that will generate a report like this:
[toddgee@toddgee.com ~]$ drupalReport.sh status toddgee.com
Site: toddgee.com
Install dir: /home/toddgee/webroot/drupal/toddgee.com
Drupal version: 6.17-dev* (tag DRUPAL-6/latest tag:DRUPAL-6-16)
Installed non-Contrib Modules: format: : {modules active from that installation}
toddgee.com: toddgee.com
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)
[toddgee@toddgee.com ~]$
The starts mean that there are pending updates.
See http://toddgee.com/drupalScripts
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.
Post new comment