Created
January 8, 2015 20:08
-
-
Save beddari/f7921d106c1390766dfc to your computer and use it in GitHub Desktop.
listdisks.sh
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