Finding Joomla Installs and Checking Version (BASH)
A small BASH script, suitable to be run as a cron job, to find Joomla installs and get the version from version.php. Can be piped into mail to generate an alert if needed
You can override the default variables by setting them within the environment. Available variables are
- PHP - The PHP binary to call (default php5-cli)
- VERSION_FILE - The Joomla version file to look for (default version.php)
- WEBDIR - The directory to search within (default /home)
- DEBUG - Enables debug mode (default n)
WEBDIR="/var/www/html"
export WEBDIR
./check_joomla_versions.sh
Details
- Language: BASH
- License: GNU GPL V2
Snippet
#!/bin/bash
#
# Check for out-of-date installs of a specific Joomla! extension
#
# Copyright (C) 2013 B Tasker
# Released under GNU GPL V2
# See http://www.gnu.org/licenses/gpl-2.0.html
#
# Set your variables here
# The filename of the manifest file used
VERSION_FILE=${VERSION_FILE:-"version.php"}
# The directory containing all your hosting accounts
WEBDIR=${WEBDIR:-"/home"}
DEBUG=${DEBUG:-"n"}
# Processing starts
cd /tmp
# Find all relevant manifests
find "$WEBDIR" -name "$VERSION_FILE" | egrep -e "cms/|joomla/" > joomla.log
while read -r joomlasite
do
major=`grep '$RELEASE' $joomlasite | sed 's/public//g' | sed 's/var//g'`
minor=`grep '$DEV_LEVEL' $joomlasite | sed 's/public//g' | sed 's/var//g'`
fullver=`php5-cli -B "$major; $minor; echo \\$RELEASE.'.'.\\$DEV_LEVEL; exit;"`
if [ "$fullver" == "." ]
then
# In Joomla 3.something these changed to constants
major=`grep 'const RELEASE' $joomlasite | sed 's/const //g' | sed 's/\t//g'`
minor=`grep 'const DEV_LEVEL' $joomlasite | sed 's/const //g' | sed 's/\t//g'`
fullver=`php5-cli -B "\\$$major; \\$$minor; echo \\$RELEASE.'.'.\\$DEV_LEVEL; exit;"`
fi
if [ "$DEBUG" == "y" ]
then
echo "DEBUG: Site is $joomlasite"
echo "DEBUG: Major is $major"
echo "DEBUG: Minor is $minor"
echo "DEBUG: Release is $fullver"
fi
echo "$joomlasite: $fullver"
done < joomla.log
rm joomla.log
Usage Example
./check_joomla_versions.sh