Commit a14b8085 authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve print_disks.sh

parent ebc950e4
#!/bin/sh
fatal()
{
echo "$*" >&2
exit 1
}
# arg: /dev/sd?
is_hdd()
{
......@@ -16,6 +22,12 @@ is_hdd()
[ "$rot" = "1" ]
}
print_dev_type()
{
is_hdd "$1" && echo "HDD" || echo "SSD"
}
# https://unix.stackexchange.com/questions/65595/how-to-know-if-a-disk-is-an-ssd-or-an-hdd
# lsblk -d -o name,rota
# NAME ROTA
......@@ -50,3 +62,4 @@ print_partsize()
[ -n "$sectors" ] || { echo "No info" ; return ; }
echo "$(($sectors/2/1024/1024)) GB"
}
......@@ -4,6 +4,9 @@ VERBOSE=
[ "$1" = "-v" ] && VERBOSE=1
. $(dirname $0)/print_disks.physorder.sh
. $(dirname $0)/functions.sh
#case "$(hostname -s)" in
# clients)
# PHYSORDER="4Q2H 6866 2690 2486 2471 0052 8696 4552 8520"
......@@ -21,18 +24,29 @@ for i in /dev/sd? ; do
SERNO=$(hdparm -i $i | grep SerialNo | sed -e "s/.*SerialNo=//g" | tail -c 5)
[ -n "$VERBOSE" ] && blkid ${i}1
LABEL=$(blkid -s LABEL ${i}1 | sed -e 's/.*LABEL="\(.*\)"/\1/')
printf "%s %6s %s\n" "$i" "$LABEL" "$SERNO" | tee -a $0.log
printf "%s %s\n" "$i" "$SERNO" | tee -a $0.log
done
health()
{
fdisk -l $1 2>/dev/null >/dev/null
}
echo >$0.log.found
echo
echo "In physical order:"
n=1
for i in $PHYSORDER ; do
if grep " $i$" $0.log ; then
printf "ata%2s. " "$n"
if grep -q " $i$" $0.log ; then
DEV="$(grep " $i$" $0.log | sed -e "s| .*||")"
health $DEV || echo "NACCESS"
printf "%s %7s %s\n" "$(print_dev_type $DEV)" "$(print_size $DEV)" "$(grep " $i$" $0.log)"
grep " $i$" $0.log >> $0.log.found
else
echo "$i is MISSED"
fi
n=$(($n+1))
done
echo
......
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