diff --git a/check_modules.sh b/check_modules.sh index 90f31ec..18d3e1f 100755 --- a/check_modules.sh +++ b/check_modules.sh @@ -1,24 +1,46 @@ #!/bin/bash -l # -# Copyright (c) 2012-2015 Christoph Niethammer +# Copyright (c) 2012-2016 Christoph Niethammer # # 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 <> $logfile cat $module_clean_env_file >> $logfile echo "--------------------" >> $logfile -for m_original in $(module av -t $moduleclass 2>&1); do - 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 ... " - echo "Checking $m_original ... " >> $logfile +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 ... " + echo "Checking $m_original ... " >> $logfile - cmd="module load $m" - echo $cmd >> $logfile - $cmd > $module_load_logfile 2>&1 - cat $module_load_logfile >> $logfile - module li >>$logfile 2>&1 - - # check if module was loaded and did not report errors during loading - if module li -t 2>&1 | grep $m >/dev/null && ! grep ERROR $module_load_logfile >/dev/null ; then - - cmd="module rm $m" + cmd="module load $m" echo $cmd >> $logfile - $cmd > $module_rm_logfile 2>&1 - cat $module_rm_logfile >> $logfile + $cmd > $module_load_logfile 2>&1 + cat $module_load_logfile >> $logfile module li >>$logfile 2>&1 - # check if module was unloaded - if module li -t 2>&1 | grep $m > /dev/null; then - echo -e "${IRed}unloading failed${Color_Off}" - echo "ERROR: unloading module '$m' failed" >> $logfile - failed_modules=(${failed_modules[@]} $m_original) + # check if module was loaded and did not report errors during loading + if module li -t 2>&1 | grep $m >/dev/null && ! grep ERROR $module_load_logfile >/dev/null ; then + + cmd="module rm $m" + echo $cmd >> $logfile + $cmd > $module_rm_logfile 2>&1 + cat $module_rm_logfile >> $logfile + module li >>$logfile 2>&1 + + # check if module was unloaded + if module li -t 2>&1 | grep $m > /dev/null; then + echo -e "${IRed}unloading failed${Color_Off}" + echo "ERROR: unloading module '$m' failed" >> $logfile + failed_modules=(${failed_modules[@]} $m_original) + else + echo -e "${IGreen}success${Color_Off}" + echo "SUCCESS" >> $logfile + fi + else - echo -e "${IGreen}success${Color_Off}" - echo "SUCCESS" >> $logfile + echo -e "${IRed}loading failed${Color_Off}" + echo "ERROR: loading module '$m' failed" >> $logfile + failed_modules=(${failed_modules[@]} $m) fi - else - echo -e "${IRed}loading failed${Color_Off}" - echo "ERROR: loading module '$m' failed" >> $logfile - failed_modules=(${failed_modules[@]} $m) + # clean up module environment + cmd="module purge" + echo $cmd >> $logfile + $cmd >>$logfile 2>&1 + module li >>$logfile 2>&1 + echo "Resetting environment ..." >>$logfile + + # Reset the complete environment manually to overcome problems with + # inconsistent internal caches of the module command after module purge. + source $module_clean_env_file 2>/dev/null + + # clean up intermediate files + rm -f $module_load_logfile + rm -f $module_rm_logfile + + echo >>$logfile 2>&1 fi - - # clean up module environment - cmd="module purge" - echo $cmd >> $logfile - $cmd >>$logfile 2>&1 - module li >>$logfile 2>&1 - echo "Resetting environment ..." >>$logfile - - # Reset the complete environment manually to overcome problems with - # inconsistent internal caches of the module command after module purge. - source $module_clean_env_file 2>/dev/null - - # clean up intermediate files - rm -f $module_load_logfile - rm -f $module_rm_logfile - - echo >>$logfile 2>&1 - fi + done done # clean up file storing the initial environment