Added support for getting drive SNs
Kyle Sheumaker [Mon, 28 Aug 2017 19:31:57 +0000 (14:31 -0500)]
etc/hardware_output.sh

index e8b6c5e..f49c9ec 100755 (executable)
@@ -12,9 +12,12 @@ disk_list() {
                dev=`basename $i`
                size=`disk_size $dev`
                model=`cat /proc/ide/$dev/model | head -1`
+               disk_sn=`disk_serialno $dev`
                echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
                echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
                echo "DISK_${DISK_COUNT}_MODEL=\"$model\""
+               echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
                DISK_COUNT=`expr ${DISK_COUNT} + 1`
        done
 
@@ -27,17 +30,48 @@ disk_list() {
                        size=`disk_size $dev`
                        model=`cat /sys/block/$dev/device/model`
                        vendor=`cat /sys/block/$dev/device/vendor`      
+                       disk_sn=`disk_serialno $dev`
                        scsi="${scsi} ### $dev:$size:$vendor $model"
 
                        echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
                        echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
                        echo "DISK_${DISK_COUNT}_MODEL=\"$vendor $model\""
+                        echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
                        DISK_COUNT=`expr ${DISK_COUNT} + 1`
                fi
        done
+
+       for i in `ls -1 /dev/nvme[0-9]+n[0-9]+$/"`
+       do
+               dev=`basename $i`
+               exists=`cat /proc/partitions | awk '{print  $4}' | grep $dev`
+               if [ "${exists}" != "" ]
+               then
+                       size=`disk_size $dev`
+                       model=`cat /sys/block/$dev/device/model`
+                       vendor=`cat /sys/block/$dev/device/vendor`      
+                       disk_sn=`disk_serialno $dev`
+                       scsi="${scsi} ### $dev:$size:$vendor $model"
+
+                       echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
+                       echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
+                       echo "DISK_${DISK_COUNT}_MODEL=\"$vendor $model\""
+                        echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
+                       DISK_COUNT=`expr ${DISK_COUNT} + 1`
+               fi
+       done
+
+
        echo "DISK_COUNT=\"${DISK_COUNT}\""
 }
 
+disk_serialno() {
+       dev=$1
+
+       sn=`hdparm -i /dev/${dev} | grep SerialNo | cut -d, -f3 | cut -d= -f2`
+       echo $sn
+}
+
 disk_size() {
        dev=$1