Ruby one-liners

Posted by chad on October 20, 2008

Dave Thomas has a great list of one-liners that are handy for command line jobs in ruby. Today I needed to setup a cron job to find all backup files that match a specific regular expression and delete them when they are 15 days old. Here’s the way I did it (yes some versions of find can do pretty much the same thing but the version that is on the RedHat server i’m using doesn’t seem to do what I want).

find | sort | ruby -pe 'next unless $_ =~ /MYFILTER/; f=$_.gsub(/n/,"");next unless File.mtime(f) < Time.now - 24*60*60*10;File.delete(f) '
Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments