Added support for multiple modules at a time and exclude pattern.

This commit is contained in:
Christoph Niethammer 2016-09-08 08:51:31 +00:00
parent 5d51934894
commit d710e1f528

View file

@ -1,24 +1,46 @@
#!/bin/bash -l
#
# Copyright (c) 2012-2015 Christoph Niethammer <niethammer@hlrs.de>
# Copyright (c) 2012-2016 Christoph Niethammer <niethammer@hlrs.de>
#
# Script checking the module environment for problems during module loading/unloading
#
# Usage:
# check_modules.sh [MODULE]
#
# Options:
# MODULE May be any valid module path as used for 'module avail [MODULE]'
#
function print_usage() {
echo <<EOT
Script checking the module environment for problems during module loading/unloading
usage: $0 [MODULE_PATTERN] [--exclude PATTERN]"
EOT
}
# Command line options:
moduleclass=$1 # check only subset of modules
declare -a moduleclasses # check only subset of modules
declare -a exclude_pattern # exclude modules with given pattern, e.g. nightly builds
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--exclude-pattern|--exclude)
exclude_patterns+=($2)
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*)
moduleclasses+=($1)
shift
;;
esac
done
# definitions for esear color output to display
Color_Off='\e[0m' # Text Reset
IGreen='\e[0;92m' # Intense Green
IRed='\e[0;91m' # Intense Red
echo Moduleclasses: ${moduleclasses[@]}
echo Exclude: ${exclude_patterns[@]}
# intermediate files, logfiles
LOGDIR=${LOGDIR:=$PWD}
tmpdir=/tmp/check_modules-$USER
@ -48,7 +70,20 @@ echo "Environment:" >> $logfile
cat $module_clean_env_file >> $logfile
echo "--------------------" >> $logfile
for m_original in $(module av -t $moduleclass 2>&1); do
for moduleclass in ${moduleclasses[@]}
do
for m_original in $(module av -t $moduleclass 2>&1); do
match=0
for exclude_pattern in ${exclude_patterns[@]}
do
if [[ "$m_original" =~ "$exclude_pattern" ]]; then
echo MATCH: $exclude_pattern
match=1
fi
done
if [ $match == 1 ]; then
continue
fi
if [[ $m_original =~ ^[A-Za-z] ]]; then # skip any non module line in output
m=$(echo $m_original | sed -e 's/(.*)//') # Remove aliases e.g. (default)
echo -n "Checking $m_original ... "
@ -102,6 +137,7 @@ for m_original in $(module av -t $moduleclass 2>&1); do
echo >>$logfile 2>&1
fi
done
done
# clean up file storing the initial environment