Topic: Rake and cron jobs


I have a couple rake tasks that are scheduled in cron and I would like to receive an email only in case any of these jobs fail. I would have no problem with that if I could suppress rake's standard output line. Can anybody give me a hint on how to do it?

Re: Rake and cron jobs


You can define a MAILTO in your cron file. Search for the second occurence of MAILTO in … ron-1.html

Hope that helps,

Re: Rake and cron jobs

Yeah, MAILTO does mail every time a job outputs anything. And rake outputs something even on successful run. What I need is to make successful runs silent smile

Re: Rake and cron jobs

Oops, sorry.

You can redirect standard output to /dev/null:

 rake my_rake_task > /dev/null # or rake my_rake_task &> /dev/null if you use bash

That's from memory, haven't tested.

Re: Rake and cron jobs

That wouldn't work either, because it would supress all the output, even if rake task fails with exception.

Tho I figured this out:

(in, that is called from cron)
cd /path/to/rails/root
export FILTER="^(\(in \/path\/to\/rails\/root|\*\* Invoke|\*\* Execute)"
export RAILS_ENV=production
rake my_task_name --trace | grep -vP "$FILTER"

Thanks smile

Last edited by bluesman.alex (2010-09-01 10:07:54)