Commit 9579d7eb authored by Vitaly Lipatov's avatar Vitaly Lipatov

rewrite print_disks.sh

parent 6890ba32
...@@ -7,30 +7,38 @@ VERBOSE= ...@@ -7,30 +7,38 @@ VERBOSE=
. $(dirname $0)/functions.sh . $(dirname $0)/functions.sh
#case "$(hostname -s)" in print_md()
# clients) {
# PHYSORDER="4Q2H 6866 2690 2486 2471 0052 8696 4552 8520" local dev="$1"
# ;; local ARRAYUUID
# *) ARRAYUUID=$(get_array_uuid_by_device $dev)
# echo "Unknown hostname $(hostname -s)" [ -n "$ARRAYUUID" ] || return
# exit 1 get_md_by_uuid $ARRAYUUID
#esac }
is_lvm()
{
blkid "$1" | grep -q "LVM2_member"
}
health()
{
fdisk -l $1 2>/dev/null >/dev/null
}
echo >$0.log echo >$0.log
# FIXME: prepare some unused cache:
for i in /dev/sd? ; do for i in /dev/sd? ; do
[ -n "$VERBOSE" ] && echo [ -n "$VERBOSE" ] && echo
[ -n "$VERBOSE" ] && hdparm -i $i | grep -B2 SerialNo | grep -v "^$" #[ -n "$VERBOSE" ] && hdparm -i $i | grep -B2 SerialNo | grep -v "^$"
SERNO=$(hdparm -i $i | grep SerialNo | sed -e "s/.*SerialNo=//g" | tail -c 5) #SERNO=$(hdparm -i $i | grep SerialNo | sed -e "s/.*SerialNo=//g" | tail -c 5)
[ -n "$VERBOSE" ] && blkid ${i}1 SERNO=$(print_serno ${i})
LABEL=$(blkid -s LABEL ${i}1 | sed -e 's/.*LABEL="\(.*\)"/\1/') #[ -n "$VERBOSE" ] && blkid ${i}1
#LABEL=$(blkid -s LABEL ${i}1 | sed -e 's/.*LABEL="\(.*\)"/\1/') #"
printf "%s %s\n" "$i" "$SERNO" | tee -a $0.log printf "%s %s\n" "$i" "$SERNO" | tee -a $0.log
done done
health()
{
fdisk -l $1 2>/dev/null >/dev/null
}
echo >$0.log.found echo >$0.log.found
echo echo
...@@ -41,7 +49,19 @@ for i in $PHYSORDER ; do ...@@ -41,7 +49,19 @@ for i in $PHYSORDER ; do
if grep -q " $i$" $0.log ; then if grep -q " $i$" $0.log ; then
DEV="$(grep " $i$" $0.log | sed -e "s| .*||")" DEV="$(grep " $i$" $0.log | sed -e "s| .*||")"
health $DEV || echo "NACCESS to $DEV" health $DEV || echo "NACCESS to $DEV"
printf "%s %7s %s\n" "$(print_dev_type $DEV)" "$(print_size $DEV)" "$(grep " $i$" $0.log)" MD="$(print_md $DEV)"
# TYPE SIZE DEV SERIAL MD
printf "%3s %7s %-10s %4s %10s\n" "$(print_dev_type $DEV)" "$(print_size $DEV)" "$DEV" "$(print_serno $DEV)" "$MD"
if [ -z "$MD" ] ; then
for pd in $DEV* ; do
MD="$(print_md $pd)"
if [ -z "$MD" ] ; then
is_lvm $pd && MD="LVM2"
fi
[ -n "$MD" ] || continue
printf " %3s %7s %-10s %4s %10s\n" "" "$(print_partsize $pd)" "$pd" "" "$MD"
done
fi
grep " $i$" $0.log >> $0.log.found grep " $i$" $0.log >> $0.log.found
else else
echo "$i is MISSED" echo "$i is MISSED"
...@@ -49,8 +69,36 @@ for i in $PHYSORDER ; do ...@@ -49,8 +69,36 @@ for i in $PHYSORDER ; do
n=$(($n+1)) n=$(($n+1))
done done
is_in_physorder()
{
local i
for i in $PHYSORDER ; do
[ "$i" = "$1" ] && return
done
return 1
}
echo
echo "Drives not in PHYSORDER:"
REALSERNO=$(cut -d" " -f2 <print_disks.sh.log | grep -v "^$")
for i in $REALSERNO ; do
is_in_physorder $i || echo " - $(grep " $i$" print_disks.sh.log)"
done
echo echo
echo "Differences:" echo "Differences:"
sort <$0.log >$0.log.sort sort <$0.log >$0.log.sort
sort <$0.log.found >$0.log.found.sort sort <$0.log.found >$0.log.found.sort
diff -u $0.log.sort $0.log.found.sort diff -u $0.log.sort $0.log.found.sort
echo
echo "Drives not in active RAID:"
for dev in /dev/sd* ; do
sdev=$(basename $dev)
# strict
cat /proc/mdstat | grep -q " $sdev\[" && continue
# use parts from it
cat /proc/mdstat | grep -q " $sdev[0-9]*\[" && continue
echo " $dev"
done
Markdown is supported
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