From: Tom Cloyd Date: 2009-05-05T17:55:04+09:00 Subject: Re: my logroll code, please critique Derek Smith wrote: > My goal is to keep 10 files each at 100Mb. Please critique and suggest > any corrections I need to make. Thank you! > > > > #!/usr/bin/ruby -w -W 2 > > require 'ftools' > require 'fileutils' > > =begin > #----------------------------- > File::LOCK_SH # shared lock (for reading) > File::LOCK_EX # exclusive lock (for writing) > File::LOCK_NB # non-blocking request > File::LOCK_UN # free lock > #----------------------------- > =end > > > ###-- 10 files at 100Mb before rolling begins ---## > > FSIZE = 104860000 > > Dir.chdir("/cygdrive/c/temp/log") \ > or raise StandardError, "Change dir failed to ~aevrlog!" > > unless File.exists?("/cygdrive/c/temp/log/zipped") > File.makedirs("zipped") \ > or raise StandardError, "Make dir failed to ~aevrlog/zipped!" > end > > array1 = Dir.glob("dev*.log") > array2 = Dir.glob("mon*.log") > array3 = Dir.glob("fer*_se*.out") > array4 = Dir.glob("fer*_se*.log") > array5 = Dir.glob("fer*_in*.log") > > if (array1.length >= 1) > array1.each { |file| > > if (File.size(file) > FSIZE) > `/usr/bin/gzip "#{file}"` > FileUtils.mv("#{file}.gz","/cygdrive/c/temp/log/zipped") > FileUtils.touch("development.log") > end > } > end > > Dir.chdir("/cygdrive/c/temp/log/zipped") \ > or raise StandardError, "Change dir failed to ~aevrlog!" > > array1_1 = Dir["/cygdrive/c/temp/log/zipped/dev*.gz"] > > if (array1_1.length >= 1) > if File.exists?("development.log.11.gz") > FileUtils.rm_r > Dir.glob("/cygdrive/c/temp/log/zipped/dev*11.gz") > end > if File.exists?("development.log.10.gz") > File.copy("development.log.10.gz", "development.log.11.gz") > end > if File.exists?("development.log.8.gz") > File.copy("development.log.8.gz", "development.log.9.gz") > end > if File.exists?("development.log.7.gz") > File.copy("development.log.7.gz", "development.log.8.gz") > end > if File.exists?("development.log.6.gz") > File.copy("development.log.6.gz", "development.log.7.gz") > end > if File.exists?("development.log.5.gz") > File.copy("development.log.5.gz", "development.log.6.gz") > end > if File.exists?("development.log.4.gz") > File.copy("development.log.4.gz", "development.log.5.gz") > end > if File.exists?("development.log.3.gz") > File.copy("development.log.3.gz", "development.log.4.gz") > end > if File.exists?("development.log.2.gz") > File.copy("development.log.2.gz", "development.log.3.gz") > end > if File.exists?("development.log.1.gz") > File.copy("development.log.1.gz", "development.log.2.gz") > end > if File.exists?("development.log.gz") > File.copy("development.log.gz", "development.log.1.gz") > end > end > Derek, I'm interested in what your trying to do here, and in the comments it's elicited. Could you share you revised code, when it's ready (or backchannel it, if you wish). I could definitely USE this! Tom