Created
April 16, 2012 13:27
-
-
Save kwilczynski/2398800 to your computer and use it in GitHub Desktop.
Check if given block device is SSD or not ...
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
#!/usr/bin/env ruby | |
rotating = [] | |
solid_state = [] | |
unknown = [] | |
block_devices = '/sys/block' | |
exclude = %w(loop.* ram.* sr.*) | |
exclude = Regexp.union(*exclude.collect { |i| Regexp.new(i) }) | |
Dir.entries(block_devices).each do |name| | |
next if ['.', '..'].include?(name) or name.match(exclude) | |
directory = File.join(block_devices, name) | |
rotation_state = File.join(directory, 'queue/rotational') | |
# This file often does not exists when system runs as virtual machine guest ... | |
if File.exists?(rotation_state) | |
File.read(rotation_state).each_line do |line| | |
line.strip! | |
# | |
# Numeric value can be: | |
# | |
# 0 -- SSD or something that does not rotate at all; | |
# 1 -- HDD or antything that physically rotates. | |
# | |
# Anything else might like different storage type ... | |
# | |
if line.match(/^1$/) | |
rotating << name | |
elsif line.match(/^0$/) | |
solid_state << name | |
else | |
unknown << name | |
end | |
end | |
end | |
end | |
p [:rotating, rotating] | |
p [:solid_state, solid_state] | |
p [:unknown, unknown] | |
# vim: set ts=2 sw=2 et : | |
# encoding: utf-8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment