Created
October 20, 2012 14:57
-
-
Save udryan10/3923492 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
def smallest_networker_group | |
#results = %x(/bin/echo -e "option regexp \n show group \n p type: NSR client; group: cloud_nonprd_*"|nsradmin -s <server> -i -|grep group:) | |
results = "cloud_nonprd_3\ncloud_nonprd_3\ncloud_nonprd_3\ncloud_nonprd_2\ncloud_nonprd_1\ncloud_nonprd_1\n" | |
results_hash = Hash.new(0) | |
#iterate over each group returned by the nsradmin command, tallying total number of times that group is used | |
results.each_line do |line| | |
group = line.gsub(/(\s+)|group:|;/,"") | |
results_hash[group] += 1 | |
end | |
# find the key of the lowest value in the hash | |
#Hash#key is not supported in ruby 1.8 | |
#smallestgroup = results_hash.key(results_hash.values.min) | |
#iterate over the hash, finding the smallest size group - is there an easier way of doing this? | |
smallest = results_hash.values.first | |
smallestgroup = results_hash.keys.first | |
results_hash.each do |k,v| | |
if(v < smallest) | |
smallest = v | |
smallestgroup = k | |
end | |
end | |
return smallestgroup | |
end | |
#call method | |
puts smallest_networker_group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment