D
Derek Smith
Hi All,
I looked through many threads for case issues and they did not help me.
I want to use case just because for this situation:
PIDF = "/usr/local/vr/prod/tmp/pids/mongrel.pid"
d = Date.today
t = Time.now
pidhash = Hash.new
pidhash[PIDF] = %x(ps auxwww |grep [m]ongrel|grep 80|awk '{print
$2}').chomp
File.open(PIDF).each do |line|
hasval = pidhash.value?(line) ### store true/false
if hasval
log_mtd("Running PID == PID in File
".+(d.to_s).+(t.hour.to_s).+(t.min.to_s))
exit
elsif (!hasval && File.size(PIDF) == 0)
puts "PID not active yet file exists", PIDF
exit
elsif (!hasval && File.size(PIDF) > 0)
puts "
exit
else
puts "no con met"
exit
end
end
I tried this syntax and it was not meeting my expected output:
So when I substitute line with a random # I expect the 2nd condition to
be printed which it is, but its not even evaling the File.size(PIDF). I
know this b/c I test it with a hard-coded file size.
hasval = pidhash.value?(7) ### store true/false
case hasval
when true
then
puts("Running PID == PID in File
".+(d.to_s).+(t.hour.to_s).+(t.min.to_s))
when (false && File.size(PIDF) == 1)
then
puts "2nd. PID not active yet file exists", PIDF
when (false && File.size(PIDF) == 0)
then
puts "3rd"
else
puts "no con met"
exit
end
test: 77 lines, 1826 characters.
[root@v /usr/local/vr/test/script]# ruby test
PID not active yet file exists
/usr/local/vr/prod/tmp/pids/mongrel.pid
[root@v /usr/local/vr/test/script]# ls -l
/usr/local/vr/prod/tmp/pids/mongrel.pid
-rw-r--r-- 1 root wheel 5 Nov 16 12:17
/usr/local/vr/prod/tmp/pids/mongrel.pid
thank you!
I looked through many threads for case issues and they did not help me.
I want to use case just because for this situation:
PIDF = "/usr/local/vr/prod/tmp/pids/mongrel.pid"
d = Date.today
t = Time.now
pidhash = Hash.new
pidhash[PIDF] = %x(ps auxwww |grep [m]ongrel|grep 80|awk '{print
$2}').chomp
File.open(PIDF).each do |line|
hasval = pidhash.value?(line) ### store true/false
if hasval
log_mtd("Running PID == PID in File
".+(d.to_s).+(t.hour.to_s).+(t.min.to_s))
exit
elsif (!hasval && File.size(PIDF) == 0)
puts "PID not active yet file exists", PIDF
exit
elsif (!hasval && File.size(PIDF) > 0)
puts "
exit
else
puts "no con met"
exit
end
end
I tried this syntax and it was not meeting my expected output:
So when I substitute line with a random # I expect the 2nd condition to
be printed which it is, but its not even evaling the File.size(PIDF). I
know this b/c I test it with a hard-coded file size.
hasval = pidhash.value?(7) ### store true/false
case hasval
when true
then
puts("Running PID == PID in File
".+(d.to_s).+(t.hour.to_s).+(t.min.to_s))
when (false && File.size(PIDF) == 1)
then
puts "2nd. PID not active yet file exists", PIDF
when (false && File.size(PIDF) == 0)
then
puts "3rd"
else
puts "no con met"
exit
end
test: 77 lines, 1826 characters.
[root@v /usr/local/vr/test/script]# ruby test
PID not active yet file exists
/usr/local/vr/prod/tmp/pids/mongrel.pid
[root@v /usr/local/vr/test/script]# ls -l
/usr/local/vr/prod/tmp/pids/mongrel.pid
-rw-r--r-- 1 root wheel 5 Nov 16 12:17
/usr/local/vr/prod/tmp/pids/mongrel.pid
thank you!