Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for mdadm, fixes #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions bht
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ typeset -a HDD_LIST=( $@ )
#print "HDD_LIST size = ${#HDD_LIST[*]}, list = ${HDD_LIST[*]}"

# check that all required external utilities are available
for p in smartctl badblocks sha256sum mkdir id lsscsi mktemp grep awk mv find mailx ps pvs
if [[ -n $EMAIL ]] ; then
EXTERNAL_UTILS="smartctl badblocks sha256sum mkdir id lsscsi mktemp grep awk mv find mailx ps pvs"
else
EXTERNAL_UTILS="smartctl badblocks sha256sum mkdir id lsscsi mktemp grep awk mv find ps pvs"
fi

for p in $EXTERNAL_UTILS
do
if ! $(which $p 2>/dev/null 1>&2) ; then
print "ERR: $p is not available or not in your PATH. please install $p and try again."
Expand Down Expand Up @@ -362,20 +368,33 @@ do
continue
fi
# make sure it is not mounted
if (( $(awk -v dev="^${HDD_LIST[i]}[0-9]+" \
if (( $(awk -v dev="^${HDD_LIST[i]}[0-9]*" \
'BEGIN{i=0} $1~dev {i++} END{print i}' /etc/mtab) > 0 )) ; then
print "WARN: ${HDD_LIST[i]} appears to be mounted. removing from list."
unset HDD_LIST[i]
continue
fi
# make sure it is not mounted via device mapper
if (( $(ls -1 /sys/block/dm-*/slaves | awk -v dev="^${HDD_LIST[i]}[0-9]*" \
'BEGIN{i=0} "/dev/" $1~dev {i++} END{print i}') > 0 )) ; then
print "WARN: ${HDD_LIST[i]} appears to be mounted via device mapper. removing from list."
unset HDD_LIST[i]
continue
fi
# make sure it is not part of a volume group
if (( $(pvs --no-headings | awk -v dev="^${HDD_LIST[i]}" \
'BEGIN{i=0} $1~dev {i++} END{print i}') > 0 )) ; then
print "WARN: ${HDD_LIST[i]} appears to be part of LVM. removing from list."
unset HDD_LIST[i]
continue
fi
## NEED TO ADD TEST TO CHECK RAID/mdraid
# make sure it is not part of an mdadm pool
if (( $(grep 'md' /proc/mdstat | tr ' ' '\n' | sed -n 's/\[.*//p' | awk -v dev="^${HDD_LIST[i]}" \
'BEGIN{i=0} "/dev/" $1~dev {i++} END{print i}') > 0 )) ; then
print "WARN: ${HDD_LIST[i]} appears to be part of a mdadm pool. removing from list."
unset HDD_LIST[i]
continue
fi
# if we have zpool, make sure this disk is not part of a ZFS pool
if $(which zpool 1>/dev/null 2>&1) && \
(( $(zpool status -L -P | awk -v dev="^${HDD_LIST[i]}" \
Expand Down