30 April 2009

Unix recursive Find and Replace

find spec ! -regex ".*.svn.*" -type f -exec grep -l "it_should_behave_like" {} \; | xargs sed -i "" "s/it_should_behave_like/#it_should_behave_like/"

Explanation:
  • find spec find in ./spec folfer
  • ! -regex ".*.svn.*" excluding .svn folders
  • -type f only files
  • -exec grep -l "it_should_behave_like" {} \; extra line to grep only files which contain "it_should_behave_like"
  • | xargs sed -i "" pipe to sed editor without creating any backup file (-i)
  • "s/ENTER OLD STRING OR TEXT TO REPLACE/ENTER REPLACEMENT STRING OR TEXT/"

29 April 2009

svn trick: revert a folder when it can not be deleted

If you ever have this error message when running
svn status
! C stories
> local delete, incoming edit upon update

=> Clean it with reverting the conflicted folder with:

svn revert stories

Setting up logrotate with capitate

How many Rails projects "forget" to set up a log rotation of their production logs and end up filling the hard disk with gigabytes of log ...

Lots ;-) And mine before I found out about logrotate.

Fortunately, there is one tool which help you to no to reinvent the wheel and set up a log rotation within minutes: capitate ;-)

Install it:

sudo gem install capitate
Add the following snippet to your conf/deploy.rb:

# See http://capitate.rubyforge.org
require 'capitate'
require 'capitate/recipes'

# Add this line but remove it afterinstalling 'cap rails:logrotate:install'
set :use_sudo, true
Run cap -T to see how many recipes you have now!

Run
cap logrotated:install_conf

It should install a new /etc/logrotate.d/rails_yourwebsite.com

/home/youruser/public_html/yourwebsite.com/shared/log/production.log {
size 10M
rotate 7
daily
missingok
notifempty
copytruncate
}


That's it!