Created
December 8, 2011 20:27
-
-
Save provegard/1448415 to your computer and use it in GitHub Desktop.
Lists Linux block devices and for each one the controller it is connected to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Lists Linux block devices and for each one the controller | |
# it is connected to. | |
set -o pipefail | |
for i in /sys/block/sd*; do | |
# Find the path that contains the PCI ID of the controller. | |
link=$(readlink $i) | |
# Assume that the PCI ID of the controller is the path part | |
# right before the /host... part. | |
parts=($(echo $link | sed -e 's,/host.*,,' | tr "/" "\n")) | |
# The PCI ID of the controller should now be the last item | |
# in the array. | |
pciid=${parts[-1]} | |
# Get the device description from the PCI ID. | |
ctrl=$(lspci -s $pciid 2>/dev/null | sed -e 's/.*: //') | |
# Print the result if lspci suceeeded (it doesn't for a block | |
# device connected to USB). | |
test $? -eq 0 && echo $i: $ctrl | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment