2012-06-05 10:26:41 +00:00
|
|
|
#!/bin/bash -l
|
2012-07-02 10:01:26 +00:00
|
|
|
#
|
2015-11-05 11:03:02 +00:00
|
|
|
# Copyright (c) 2012-2015 Christoph Niethammer <niethammer@hlrs.de>
|
2012-07-02 10:01:26 +00:00
|
|
|
#
|
2012-07-31 22:04:46 +00:00
|
|
|
# Script checking the module environment for problems during module loading/unloading
|
2015-11-05 11:03:02 +00:00
|
|
|
#
|
2012-07-31 22:04:46 +00:00
|
|
|
# Usage:
|
|
|
|
# check_modules.sh [MODULE]
|
|
|
|
#
|
|
|
|
# Options:
|
|
|
|
# MODULE May be any valid module path as used for 'module avail [MODULE]'
|
2012-07-02 10:01:26 +00:00
|
|
|
#
|
2012-06-05 10:26:41 +00:00
|
|
|
|
2015-11-05 11:03:02 +00:00
|
|
|
# Command line options:
|
|
|
|
moduleclass=$1 # check only subset of modules
|
2012-07-31 22:04:46 +00:00
|
|
|
|
2015-11-05 11:03:02 +00:00
|
|
|
# definitions for esear color output to display
|
2012-07-31 22:04:46 +00:00
|
|
|
Color_Off='\e[0m' # Text Reset
|
|
|
|
IGreen='\e[0;92m' # Intense Green
|
|
|
|
IRed='\e[0;91m' # Intense Red
|
2012-06-05 10:26:41 +00:00
|
|
|
|
2012-07-31 22:04:46 +00:00
|
|
|
# intermediate files, logfiles
|
2013-03-13 11:01:32 +00:00
|
|
|
LOGDIR=${LOGDIR:=$PWD}
|
2013-03-13 11:11:57 +00:00
|
|
|
tmpdir=/tmp/check_modules-$USER
|
|
|
|
mkdir -p $tmpdir
|
2013-03-13 11:01:32 +00:00
|
|
|
logfile="$LOGDIR/check_modules.log" # logfile with detailed information
|
2015-11-05 11:03:02 +00:00
|
|
|
module_load_logfile="$tmpdir/.module_load.log" # output of 'module load commands
|
2013-03-13 11:11:57 +00:00
|
|
|
module_rm_logfile="$tmpdir/.module_rm.log" # output of 'module rm' commands
|
|
|
|
module_clean_env_file="$tmpdir/.module_clean_env" # original environment
|
2012-07-31 22:04:46 +00:00
|
|
|
|
|
|
|
# safe the original environment
|
|
|
|
set > $module_clean_env_file
|
|
|
|
|
|
|
|
# list of all failed modules
|
|
|
|
failed_modules=()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "--------------------" | tee $logfile
|
|
|
|
echo "Module environment check" | tee -a $logfile
|
|
|
|
echo "--------------------" | tee -a $logfile
|
|
|
|
echo "Date: $(date)" | tee -a $logfile
|
|
|
|
echo "Host: $(/bin/hostname)" | tee -a $logfile
|
|
|
|
echo "USER: $USER" | tee -a $logfile
|
|
|
|
echo "Logfile: $logfile" | tee -a $logfile
|
|
|
|
echo "--------------------" | tee -a $logfile
|
|
|
|
echo "Environment:" >> $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)
|
2015-11-05 11:03:02 +00:00
|
|
|
echo -n "Checking $m_original ... "
|
2012-07-31 22:04:46 +00:00
|
|
|
echo "Checking $m_original ... " >> $logfile
|
|
|
|
|
|
|
|
cmd="module load $m"
|
|
|
|
echo $cmd >> $logfile
|
2015-11-05 11:03:02 +00:00
|
|
|
$cmd > $module_load_logfile 2>&1
|
2012-07-31 22:04:46 +00:00
|
|
|
cat $module_load_logfile >> $logfile
|
|
|
|
module li >>$logfile 2>&1
|
|
|
|
|
|
|
|
# check if module was loaded and did not report errors during loading
|
2015-11-05 11:03:02 +00:00
|
|
|
if module li -t 2>&1 | grep $m >/dev/null && ! grep ERROR $module_load_logfile >/dev/null ; then
|
2012-07-31 22:04:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-11-05 11:03:02 +00:00
|
|
|
else
|
2012-07-31 22:04:46 +00:00
|
|
|
echo -e "${IRed}loading failed${Color_Off}"
|
|
|
|
echo "ERROR: loading module '$m' failed" >> $logfile
|
2012-07-02 10:01:26 +00:00
|
|
|
failed_modules=(${failed_modules[@]} $m)
|
2012-06-05 10:26:41 +00:00
|
|
|
fi
|
2012-07-31 22:04:46 +00:00
|
|
|
|
|
|
|
# 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
|
2012-07-02 10:01:26 +00:00
|
|
|
rm -f $module_load_logfile
|
2012-07-02 11:14:25 +00:00
|
|
|
rm -f $module_rm_logfile
|
2012-07-31 22:04:46 +00:00
|
|
|
|
|
|
|
echo >>$logfile 2>&1
|
2012-06-05 10:26:41 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-11-05 11:03:02 +00:00
|
|
|
# clean up file storing the initial environment
|
2012-07-31 22:04:46 +00:00
|
|
|
rm -f $module_clean_env_file
|
2013-03-13 11:11:57 +00:00
|
|
|
rm -rf $tmpdir
|
2012-07-31 22:04:46 +00:00
|
|
|
|
|
|
|
|
2012-07-02 10:01:26 +00:00
|
|
|
echo "----------------------------------------"
|
2012-07-31 22:04:46 +00:00
|
|
|
echo "Summary of failed modules (${#failed_modules[@]}):"
|
2012-07-02 10:01:26 +00:00
|
|
|
echo "----------------------------------------"
|
|
|
|
for m in ${failed_modules[@]}; do
|
|
|
|
echo "$m"
|
|
|
|
done
|
|
|
|
echo "----------------------------------------"
|
2012-07-31 22:04:46 +00:00
|
|
|
|