Forum: Ruby Script which deletes and comprisses logfiles

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

Can somebody show me how do I write a script which compresses my old log
files (older than 3 months) and delete them also?

Greetings
rubyamateur
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2017-03-22 14:32
I wonder why you want to do it in Ruby, because this is such a typical
shell script task: Use 'find' for locating the old files, 'zip' to
compress them, and 'rm' to remove the unused ones.

Of course, you can do it in Ruby too:

The Ruby equivalent to find is the class Find,
http://ruby-doc.org/stdlib-2.2.4/libdoc/find/rdoc/Find.html

Compressing is done by Zlib,
http://ruby-doc.org/stdlib-2.4.0/libdoc/zlib/rdoc/Zlib.html

I don't think deleting a file will cause you problems....
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.