Need help to get output

Hi
I am quite new to ruby and i need to get couple of output with bellow
Result

i need something like

member0 Slot 0 Memory utilization 30
member0 Slot 1 Memory utilization 30
member1 Slot 0 Memory utilization 30
member1 Slot 1 Memory utilization 30

if i get the those out put, i will be able to get rest …
Can any one please give me some light

Thanks

member0:

Slot 0:
Routing Engine status:
Temperature 26 degrees C / 78 degrees F
CPU temperature 51 degrees C / 123 degrees F
DRAM 2048 MB
Memory utilization 30 percent
CPU utilization:
User 0 percent
Real-time threads 7 percent
Kernel 4 percent
Idle 89 percent
Model RE-J6350-3400
Serial ID NM1742
Start time 2008-04-29 16:56:46 UTC
Uptime 2 minutes, 20 seconds
Load averages: 1 minute 5 minute 15 minute
0.08 0.07 0.03

Routing Engine status:
Slot 1:
Temperature 26 degrees C / 78 degrees F
CPU temperature 51 degrees C / 123 degrees F
DRAM 2048 MB
Memory utilization 30 percent
CPU utilization:
User 0 percent
Real-time threads 7 percent
Kernel 4 percent
Idle 89 percent
Model RE-J6350-3400
Serial ID NM1742
Start time 2008-04-29 16:56:46 UTC
Uptime 2 minutes, 20 seconds
Load averages: 1 minute 5 minute 15 minute
0.08 0.07 0.03

member1:

Slot 0:
Routing Engine status:
Temperature 26 degrees C / 78 degrees F
CPU temperature 51 degrees C / 123 degrees F
DRAM 2048 MB
Memory utilization 30 percent
CPU utilization:
User 0 percent
Real-time threads 7 percent
Kernel 4 percent
Idle 89 percent
Model RE-J6350-3400
Serial ID NM1742
Start time 2008-04-29 16:56:46 UTC
Uptime 2 minutes, 20 seconds
Load averages: 1 minute 5 minute 15 minute
0.08 0.07 0.03

Routing Engine status:
Slot 1:
Temperature 26 degrees C / 78 degrees F
CPU temperature 51 degrees C / 123 degrees F
DRAM 2048 MB
Memory utilization 30 percent
CPU utilization:
User 0 percent
Real-time threads 7 percent
Kernel 4 percent
Idle 89 percent
Model RE-J6350-3400
Serial ID NM1742
Start time 2008-04-29 16:56:46 UTC
Uptime 2 minutes, 20 seconds
Load averages: 1 minute 5 minute 15 minute
0.08 0.07 0.03

I would be really grateful if any one can help me with a script

thanks

member,slot="",""
File.readlines(ARGV[0]).each do |linecrlf|
line = linecrlf.chomp
case line
when /^member/ then member=line
when /^Slot/ then slot=line
when /Memory utilization/
puts “%10s %10s %s” % [member,slot,line.gsub(/\s+percent/,"%")]
end
end

ruby router_check.rb
router_check.rb:10: invalid regular expression; there’s no previous
pattern, to which ‘+’ would define cardinality at 3: /\b+percent/

try with /\s+percent/

Regis d’Aubarede wrote in post #1074491:

member,slot="",""
File.readlines(ARGV[0]).each do |linecrlf|
line = linecrlf.chomp
case line
when /^member/ then member=line
when /^Slot/ then slot=line
when /Memory utilization/
puts “%10s %10s %s” % [member,slot,line.gsub(/\s+percent/,"%")]
end
end

Hi thanks
I put those output in a router file

so i edited like this

#!/usr/bin/ruby

member,slot="",""
File.readlines(“router”).each do |linecrlf|
line = linecrlf.chomp
case line
when /^member/ then member=line
when /^Slot/ then slot=line
when /Memory utilization/
puts “%10s %10s %s” % [member,slot,line.gsub(/\b+percent/,"%")]
end
end

but it shows

ruby router_check.rb
router_check.rb:10: invalid regular expression; there’s no previous
pattern, to which ‘+’ would define cardinality at 3: /\b+percent/

I’m not as good at Ruby notation, but does this modification do what you
want?

member,slot,outputstring="","",""
File.readlines(ARGV[0]).each do |linecrlf|
line = linecrlf.chomp
case line
when /^member/ then member=line
when /^Slot/ then slot=line
when /Memory utilization/
outputstring = “#{outputstring}#{member} #{slot} #{line}\n”
end
end

puts outputstring.gsub(/:/,"").gsub(/\s+percent/,"").gsub(/ +/," ")

Regis d’Aubarede wrote in post #1074497:

ruby router_check.rb
router_check.rb:10: invalid regular expression; there’s no previous
pattern, to which ‘+’ would define cardinality at 3: /\b+percent/

try with /\s+percent/

hi thanks
its work
only problem is Slot is not showing

how can i fix that ??

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs