Loop through a line between words

Hi
I would be really great full , if any one can give me some light on how
to progress on bellow.

i am familiar with simple loop but this one seems complex.
Basically i am trying to do the something in bellow link but with ruby

https://github.com/opinkerfi/nagios-plugins/blob/master/check_dataprotector/check_dp_tablespace

( I don’t need full solution, i just need help with start the program)

Thanks for your help
i want to loop through some lines but condition will be :-

1)loop will start if line has word call “Base”
2) if it see a line has word
“Maximum size with extensions”
“Current size with extensions”
it will separate the value( I know how to do that )

  1. It will scan lines till it finds a word call “Current size”
  2. it will then escape all line until it find another word call “Base”
    and will do the same till word call “Current Size”

Example :

Base file “dirs.dat”:
Device = /var/opt/omni/server/db40/datafiles/cdb
Number of extensions = 0
Maximum size = 2096128 [kB]
Current size = 88896 [kB]
Maximum size with extensions = 2096128 [kB]
Current size with extensions = 88896 [kB]

Base file “fn1.ext”:
Device = /var/opt/omni/server/db40/datafiles/cdb
Number of extensions = 0
Maximum size = 2096128 [kB]
Current size = 216640 [kB]
Maximum size with extensions = 2096128 [kB]
Current size with extensions = 216640 [kB]

if any one can help with Looping part… that will be really good .

Thanks

Fosiul A. wrote in post #1143150:

Hi
I would be really great full , if any one can give me some light on how
to progress on bellow.

something like that ?

h={}
fname=“unknown”
File.read(IN).split(/\n/).each do |line|
label,value=line.split(/\s*=\s*/,2)
ivalue=value.scan(/\d+/).first.to_i if value

case line
when /^Base/
fname=line.scan(/(")(.*?)(")/).first[1] || “unknown”
h[fname]={max:-1,cur: -1}
when /^Maximum size with extensions/ then h[fname][:max]=ivalue
when /^Current size with extensions/ then h[fname][:cur]=ivalue
end
end
p h

{“dirs.dat”=>{:max=>2096128, :cur=>88896}, “fn1.ext”=>{:max=>2096128,
:cur=>216640}}

Hi
the output looks really good,

{“dirs.dat”=>{:max=>2096128, :cur=>88896}, “fn1.ext”=>{:max=>2096128,
:cur=>216640}}

but when i am executing i having issues here …

 h[fname]={max:-1,cur: -1}

the error i get, is bellow :-

syntax error, unexpected tSYMBEG, expecting kDO or ‘{’ or ‘(’
h[fname]={max:-1,cur: -1}
^

I am using ruby 1.8

Please advise.

Fosiul A. wrote in post #1143174:

Hi

So VSOP syntax is :

h[fname]={:max => -1,:cur => -1}

Regis d’Aubarede wrote in post #1143175:

Nice one mate!!
thanks

So VSOP syntax is :

h[fname]={:max => -1,:cur => -1}

let me play with it now

just wanted to know

what does bellow line mean ? can i have a related ruby document for this

h[fname]={:max => -1,:cur => -1}

Fosiul A. wrote in post #1143176:

Regis d’Aubarede wrote in post #1143175:

can i have a related ruby document for this

http://www.tutorialspoint.com/ruby/ruby_hashes.htm

google: ruby book …

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