Here's the entire code, including invocation from ksh:
ruby <<'!*'
class String
def String.comment (str)
str =~ /^(#| *$)/
end
end
class Time
def Time.datein (str)
dayx = Time.now.wday
wdays = %w(Sun Mon Tue Wed Thu Fri Sat)
weekday = (dayx > 0 && dayx < 6)
weekend = ! weekday
( ((str =~ /(#{wdays[dayx]}|"^$"|"All")/) != nil) ||
(str =~ "Weekday" && weekday) ||
(str =~ "Weekend" && weekend))
end
end
File.open(ENV["ORACONF"]) { |conf|
conf.readlines.each { |line|
next if String.comment(line)
line.chomp!
instance, days, startup, cm, backup = line.split(":")
print instance, " " if Time.datein(days)
# print("Backup ", instance, "? ", Time.datein(days), "\n")
}
}
!*
The code is supposed to scan for the name of an Oracle instance, and report if it should be backed up on that day or not (thus "datein"). The use of "print" instead of "exit" is so all databases to be backed up can be reported and put into an environment variable.
By the way, I noticed that not only can you NOT create an environment variable (Surprise!) but there doesn't seem to be a way to get the value to the parent shell without nasty trickery (not a surprise to this long time shell programmer....)
>>> Dave Thomas <Dave / thomases.com> 03/15/00 02:44PM >>>
"David Douthitt" <DDouthitt / cuna.com> writes:
> If I change the snippet as recommended (twice over!) I get:
>
> -:9: undefined local variable or method `comment?' for #<Object:0x40061860> (NameError)
> from -:8:in `each'
> from -:8
> from -:7:in `open'
> from -:7
That means that 'line' is type Object, and not a String. This is very
strange. Could you possibly post the failing code so we can try it
here?
Thanks
Dave