Monday, November 27, 2006

Useful: latest

I reinstalled my computer from the ground up recently. This has given me a lot of opportunity to question, rethink and automate my day-to-day activities.

As part of my ongoing effort to redeploy my rails applications to my production environment in the most intelligent hands-off way, I've been looking for a way to "detect" the latest deployment.

Here's the script that resulted:

#!/usr/bin/env ruby
$VERBOSE = true

pattern = ARGV[0]
pattern ||= '*'

latest = Dir.glob(pattern).sort_by {|f| File.mtime(f)}.last

puts latest unless latest.nil?

It takes, optionally, a bash-style glob. ( latest 'booktrack*' )

I'm finding it surprisingly useful. Let me know if it helps you out.

0 Comments:

Post a Comment

<< Home