From: sto.mar@... Date: 2013-07-30T21:50:11+09:00 Subject: Re: Question about arrays/hash Am 30.07.2013 14:40, schrieb Jenn Fo: > Hi All: > > I am new to ruby so I am stuck on a piece of code. I am trying to > create a plugin check (see below). > The end result if a failed drive or drives are present to print the > following: > > Failed Drive: 1I:1:2, 1E:3:24 > > However, due to the way I wrote the code, it's only including the first > drive. I would appreciate any tips on what I should be doing! :D > > def check_array > slots=%x[/usr/sbin/hpacucli controller all show] > slots.each_line do |s| > s =~ /([Slot ][\d]{1,2})/ > no = $1 > no = no.lstrip if no > drives=%x[/usr/sbin/hpacucli controller slot=#{no} physicaldrive > all show] > drives.each_line do |line| > drive =[] > f = > /([0-9]{1,2}[a-zA-Z]{1,2}:[0-9]{1,2}:[0-9]{1,2})(.*)Failed(.*)/.match(line) > drive << f.captures[0] if f > end > critical "Failed Drive: #{drive}" > end The problem is that you reset `drive' to an empty array in each iteration. Regards, Marcus -- GitHub: https://github.com/stomar/ PGP: 0x6B3A101A