Skip to content
Snippets Groups Projects
diskPosition2 883 B
Newer Older
root's avatar
root committed
#!/bin/sh

# Display drive bay for disks connected to SAS expander backplane

for name in /sys/block/* ; do

  lbl_d=$(basename $name)

  #echo $lbl_d

  npath=$(readlink -f $name)

  #echo $npath

  while [ $npath != "/" ] ; do

    npath=$(dirname $npath)

    ep=$(basename $npath)

    if [ -e $npath/sas_device/$ep/bay_identifier ] ; then

      if cat $npath/sas_device/$ep/bay_identifier > /dev/null 2>&1; then

        bay=$(cat $npath/sas_device/$ep/bay_identifier)
        encl=$(cat $npath/sas_device/$ep/enclosure_identifier)
        sn=$(smartctl -i /dev/$lbl_d | grep "Serial")

        vendor=$(smartctl -i /dev/$lbl_d | grep "Vendor")
        product=$(smartctl -i /dev/$lbl_d | grep "Product")

        echo "$name Enclosure: $encl BayID: $bay - $sn - $vendor $product"
        echo "$npath/sas_device/$ep"
        echo ""

        break
      fi
    fi
  done
done