Forum: Ruby Delete and compress logfiles

B8c0fa903537801d9268fc77b98e0039?d=identicon&s=25 Ruby Amateur (rubyamateur)
on 2017-03-29 09:03
Hello, together
Since last month I work with Ruby.
I realised that I leave in the work often log files which are older than
1 month.
Now I want to delete them, however, a ruby script would be more sensible
there.

I know, I can do that in shell, but I want it in ruby.

Can someone send me a example script who does that?
Greetings
rubyamateur
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2017-03-29 20:08
Ruby Amateur wrote in post #1185726:
> Hello, together
> Since last month I work with Ruby.
> I realised that I leave in the work often log files which are older than
> 1 month.
> Now I want to delete them, however, a ruby script would be more sensible
> there.



last_month= Date.today << 1
Dir.glob("*.log").select {|f|
   File.mtime(f).to_date < last_month
}.each {|f|
  File.delete(f)
}
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.