Created
June 4, 2015 06:00
-
-
Save mikehale/467da07307e58a0059b1 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# Shows the physical location of each disk | |
DEVICE_NAME = "sata_sil24" | |
FORMAT = { | |
:scsi_id => 0..12, | |
:media => 13..20, | |
:bus => 21..29, | |
:model => 30..46, | |
:rev => 47..52, | |
:dev => 53..63, | |
:size => 64..71, | |
} | |
def device_to_id(device) | |
Dir["/dev/disk/by-id/ata-*"].entries.detect do |e| | |
File.readlink(e) =~ /#{File.basename(device)}$/ | |
end || "<>" | |
end | |
devices = `lsscsi -H`.split($/). | |
map{|l| l.scan(/\[(\d+)\]\s+(\S+)/) }. | |
map(&:first). | |
select{|d| d[1] == DEVICE_NAME }.map(&:first) | |
info = `lsscsi -s`.split($/).map do |l| | |
m = {} | |
FORMAT.each {|key, index| | |
m[key] = l[index].strip | |
} | |
m[:scsi_id] = m[:scsi_id].scan(/\[(\d:\d):\d:\d\]/).first.first | |
m[:dev] = device_to_id(m[:dev]) | |
m | |
end | |
tower_devices = info.select{|i| i[:scsi_id] =~ /#{devices.join("|")}/}.sort_by{|i| i[:scsi_id] } | |
puts "|----------------------------------------------------------------------|" | |
tower_devices.each do |i| | |
data = [ | |
i[:scsi_id].ljust(4), | |
i[:dev].ljust(56), | |
i[:size].rjust(8) | |
].join(" ") | |
puts "|#{data}|" | |
puts "|----------------------------------------------------------------------|" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment