Commit ae786f01 authored by Dan Reading's avatar Dan Reading
Browse files

major refactoring, just a checkpoint with getdisknames working

parent 5b583443
......@@ -8,7 +8,6 @@ echo -n ' Starting diskcheck..'
# first arg is the log output file, if not set then /tmp/...
#Global
declare SMARTCTL=''
declare failed=""
declare error=""
declare err=""
......@@ -17,49 +16,52 @@ source getfromtb.sh
source hbis.sh
source checkutils.sh
main() {
inithostname
initlogs $@
SMARTCTL=$(findSmartctl)
drivenames=$(getdrivenames)
if [ -z "$drivenames" ] ; then
echo "No drives found. exit"
exit 1
fi
# setup logging
if [ $1 ] ; then
logfile=$1
else
logfile="/tmp/nodecheck.log"
fi
#exit on unbound var, set after sourcing files
set -u
os=`uname -s`
host=`hostname`
if [ -e "/var/emulab/boot/realname" ]; then
host=`cat /var/emulab/boot/realname`
fi
tmplog=/tmp/.$$.log
cat /dev/null > ${tmplog}
#XXX XXX disknames=$(getdriveinfo ${logout} ${tmpout})
#XXX XXX ## echo disknames:$disknames
#XXX XXX cat ${tmpout} ; rm -f ${tmpout}
#XXX XXX echo "diskcheck `date`" >> ${logfile}
#XXX XXX cat ${logout} >> ${logfile} ; rm -f ${logout}
tmpout=/tmp/.$$tmpout.log ; touch ${tmpout}
logout=/tmp/.$$logout.log ; touch ${logout}
#echo "" ; echo -n "$0:${LINENO} " ; echo drivenames:${disknames}:
disknames=$(getdriveinfo ${logout} ${tmpout})
cat ${tmpout} ; rm -f ${tmpout}
echo "diskcheck `date`" >> ${logfile}
cat ${logout} >> ${logfile} ; rm -f ${logout}
#turn string into array
#XXX XXX unset -v scan; declare -a scan=(${drivename// / })
#echo "" ; echo -n "$0:${LINENO} " ; echo disknames:${disknames}:
if [ -z "$disknames" ] ; then
echo "No drives found. exit"
exit 1
fi
#echo -n "$0:${LINENO} " ; echo scan:"${scan[@]}":
unset -v scan; declare -a scan=(${disknames// / })
# the index into dirveinv array
name=0; driver=1; type=2; size=3; temp=4;
model=5; serial=6; bpers=7; sectors=8;
echo -n "$0:${LINENO} " ; echo scan:"${scan[@]}":
# array to put drive inventory
unset -v driveinv ; declare -a driveinv=()
# array of drives to hold each drive inventory
echo ""
echo "drivenames:||$drivenames||"
unset -v drive ; declare -a drive=($drivenames)
# the index into dirveinv array
name=0; driver=1; type=2; size=3; temp=4; model=5; serial=6;
unset -v driveinv ; declare -a driveinv=()
numberofdrives=${#drive[*]}
echo len=$len
for (( i = 0; i < $len ; i++ )) ; do
echo drive:$i = ${drive[$i]}
done
exit
#now split up each line using 'device' into the array drivescan
# This is an example of the string we are parsing:
......@@ -231,6 +233,97 @@ echo -n "Have $havecnt drive"
cat ${tmplog} >> $logfile
cat ${tmplog}
}
getdriveinfo () {
#need to make sure smartcrl is installed
{
# echo -n "${FUNCNAME[0]}:${LINENO} " ; echo "args::$@::"
declare buildscan=""
logout="$1"
tmpout="$2"
if [ "${SMARTCTL}" != "$NOSM" ] ; then
rtn=$($SMARTCTL --scan)
# unrecongnized
if [ -n "$(echo $rtn | grep 'UNRECOGNIZED OPTION')" ] ; then
error="(smartctl option '--scan' not supported. Attempt alternet method) "
err=scan
elif [ -n "$(echo $rtn | grep -v 'device')" ] ; then
# output in unexpected format - missing deliminator "device"
error="(smartctl option '--scan' strange ouput. Attempt alternet method) "
err=scan
# empty
elif [ -z "$rtn" ] ; then
dt=$(df / | grep /dev)
dt=${dt:5}
dt=${dt%% *}
error="(smartctl device_type '$dt' not supported"
err=device
fi
[[ $error ]] && echo "$error"
else
error="smartmontools missing."
err="missing"
echo "$error. FAIL "
fi
} > ${logout} 2>&1
# put smartctl --scan into driveinv array
# a better control flow control could be used
placeholder=" . . . . . device"
case $err in
scan | missing | device )
case $os in
Linux )
list="a b c d e f g h i j k l m n o p"
for i in $list
do
if [ -b /dev/sd${i} ] ; then
buildscan+="/dev/sd${i} $placeholder"
fi
done
;;
FreeBSD )
list="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
for i in $list
do
[[ -b /dev/da${i} ]] && buildscan+="/dev/da${i} $placeholder "
[[ -c /dev/ad${i} ]] && buildscan+="/dev/ad${i} $placeholder "
[[ -c /dev/amrd${i} ]] && buildscan+="/dev/amrd${i} $placeholder "
done
;;
* )
echo "${FUNCNAME[0]}:${LINENO} Internal error"
exit
;;
esac
unset -v scan
[[ $buildscan ]] && declare -a scan=($buildscan) || declare -a scan=("")
# echo -n "${FUNCNAME[0]}:${LINENO} " ; echo "buildscan::${buildscan}::"
;;
root )
echo -n "$error. FAIL " >> ${tmpout}
echo "Last attempt return roots mount point" >> ${tmpout}
x=$(df / | grep /dev)
lastattempt="${x%% *} $placeholder "
unset -v scan ; declare -a scan=($lastattempt)
;;
* )
# get the output of --scan into array scan
unset -v scan ; declare -a scan=($rtn)
# echo -n "${FUNCNAME[0]}:${LINENO} " ; echo "rtn::${rtn}::"
;;
esac
# the result
echo -n "${scan[@]}"
}
main $@
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment