Configuring MAILTO

984 views
Skip to first unread message

Wojciech Wnętrzak

unread,
Sep 7, 2010, 2:44:01 AM9/7/10
to Whenever Gem
Hi.

Is there a way to configure instance variable MAILTO using whenever
gem?
I would like to specify where to send email with cron output.

Javan Makhmali

unread,
Sep 7, 2010, 10:08:06 AM9/7/10
to whenev...@googlegroups.com
In your schedule.rb:

env :MAILTO, 'some...@example.com'

Javan

> --
> You received this message because you are subscribed to the Google
> Groups "Whenever Gem" group and because you're awesome.
> To post to this group, send email to whenev...@googlegroups.com
> To unsubscribe from this group, send email to
> whenever-gem...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/whenever-gem?hl=en

Wojciech Wnętrzak

unread,
Sep 8, 2010, 9:38:43 AM9/8/10
to Whenever Gem

Thanks, it's working.

It would be nice to have this example in gem README or in default
schedule.rb file.

Bruno Duyé

unread,
Sep 20, 2010, 9:07:50 AM9/20/10
to Whenever Gem
Added to Github wiki

Bruno Duyé

unread,
Sep 20, 2010, 12:44:01 PM9/20/10
to Whenever Gem
I tried to find a solution for having email sent with whenever when
something written if stderr; but without success (I'm using rake
jobtype).

Why rake jobtype adds "2>&1" at the end of the generated crontab
lines ? This prevents cron from getting the stderr outputs and send it
by email; so the MAILTO becomes useless.
A primary solution for that could be a syntax like :

* * * * * (cd /var/rails/my_app && RAILS_ENV=production /usr/bin/env
rake test >> /var/rails/my_app/log/cron.log) | tee /var/rails/my_app/
log/cron_errors.log

The use of tee command allow the catching of std_err and email sending
by cron.

I suppose that an other way would be to define a new job_type;
something like
job_type :rake_with_error_mail, "(cd #{RAILS_ROOT} && /usr/bin/env
rake utils:test >> #{RAILS_ROOT}/log/cron.log) | tee #{RAILS_ROOT}/log/
cron_errors.log"
or something like that.
But I've an error after upgrading from 0.4.1 to 0.5.2 :
/home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/job_list.rb:
24:in `initialize': /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/
activesupport-2.3.5/lib/active_support/dependencies.rb:105:in
`const_missing': uninitialized constant Whenever::JobList::RAILS_ROOT
(NameError)
from (eval):8:in `initialize'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
base.rb:4:in `eval'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
job_list.rb:24:in `initialize'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
base.rb:4:in `new'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
base.rb:4:in `cron'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
command_line.rb:42:in `run'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/lib/whenever/
command_line.rb:8:in `execute'
from /home/bduye/.gem/ruby/1.8/gems/whenever-0.5.2/bin/whenever:35
from /opt/ruby-enterprise/bin/whenever:19:in `load'
from /opt/ruby-enterprise/bin/whenever:19


Why couldn't it be possible to use RAILS_ROOT constant inside
whenever ? Just opened a ticket for that :
http://github.com/javan/whenever/issues/issue/81

Javan Makhmali

unread,
Sep 20, 2010, 6:25:12 PM9/20/10
to whenev...@googlegroups.com
Take a look at the wiki page on logging:
http://github.com/javan/whenever/wiki/Output-redirection-(logging-your-cron-jobs)

The "2>&1" is only being added because you have set up logging for both stdout and stderr. I believe if you just capture stdout, stderr will still get emailed to your MAILTO.

I responded to your github issue as well.

Javan

Bruno Duyé

unread,
Sep 21, 2010, 4:18:27 AM9/21/10
to Whenever Gem
Thanks, this is right.
The way to get stderr to en email is to configure like :

env :MAILTO, 'te...@siliconsalad.com'
set :output, {:standard => "a/log/cron.log"}


But we get nothing on the log file about errors.
What do you think about what I said on my precedent mail :
- adding a way to use tee command when user wants to get stdout and
stderr on log files AND to redirect it to cron as well ?
- or maybe using fyi for cron alerts : http://github.com/airblade/fyi


Thanks for your answers

On 21 sep, 00:25, Javan Makhmali <ja...@javan.us> wrote:
> Take a look at the wiki page on logging:http://github.com/javan/whenever/wiki/Output-redirection-(logging-you...)
Reply all
Reply to author
Forward
0 new messages