Created
October 5, 2016 02:22
-
-
Save misshie/9d00f55859c51f1afb1734625037e919 to your computer and use it in GitHub Desktop.
Blink all locate LEDs of an SAS-enclosure binded to a block device
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 | |
# | |
# Blink all locate LEDs of an SAS-enclosure binded to a block device | |
# Hiroyuki Mishima ([email protected]) | |
# | |
require 'optparse' | |
class BlinkEnclosure | |
PARALLEL = "parallel -j1" | |
def dev(path) | |
path.sub(/\/dev\//,'') | |
end | |
def enc(path) | |
File.join(Dir[path].first.split("/")[0..4]) | |
end | |
def on(loc) | |
cmd = "bash -c '#{PARALLEL} echo 1 \\> {} ::: #{loc}'" | |
puts cmd | |
system cmd | |
end | |
def off(loc) | |
cmd = "bash -c '#{PARALLEL} echo 0 \\> {} ::: #{loc}'" | |
puts cmd | |
system cmd | |
end | |
def run(opts) | |
case | |
when opts["on"] | |
epath = enc("/sys/class/enclosure/*/*/device/block/#{dev(opts["on"])}") | |
on("#{epath}/*/locate") | |
when opts["off"] | |
epath = enc("/sys/class/enclosure/*/*/device/block/#{dev(opts["off"])}") | |
off("#{epath}/*/locate") | |
else | |
raise "unknown option" | |
end | |
end | |
end | |
if $0 == __FILE__ | |
BlinkEnclosure.new.run(ARGV.getopts("", "on:", "off:")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment