# X-Files ?  strange ! script behaves differently when running as cron task....

**URL:** <https://discuss.rubyonrails.org/t/x-files-strange-script-behaves-differently-when-running-as-cron-task/57958>\
**Category:** rubyonrails-talk\
**Created:** [March 17, 2011, 3:25pm UTC](https://discuss.rubyonrails.org/t/x-files-strange-script-behaves-differently-when-running-as-cron-task/57958 "2011-03-17T15:25:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [March 17, 2011, 3:25pm UTC](https://discuss.rubyonrails.org/t/x-files-strange-script-behaves-differently-when-running-as-cron-task/57958/1 "2011-03-17T15:25:42Z")

</div>

I am running a ruby script ( 1.9.2, w Rails3 gems) this script reads 2 different pop3 mailboxes then send back emails to senders with a specific link in the email body... for testing I send one email in each mailboxes joinus@domain.com and unase@domain.es

running the script in the server console is fine .... the 2 mailboxes are read, and each sender receives back the corresponding responses

then I created a cron task to run THIS same script every 5 min

/5 \* \* \* \* bash -c "source /usr/local/rvm/scripts/rvm && rvm gemset use rails3 && /usr/bin/env ruby /var/www/../current/jmy\_app/ joinus\_email.rb"

the script is launched correctly, my info log shows the notifier being processed for each email as above , BUT only the first email response is delivered....

as the script runs well in the console, I don't know where to start looking for some weird coding ... I have the following setup :

my\_app\_folder - joinus\_email folder &nbsp;&nbsp;&nbsp;&nbsp;- joinus\_email.rb &nbsp;&nbsp;&nbsp;&nbsp;- notifier folder &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-notifiers..html.erb

I defined the ActionMailer::Base.smtp\_settings in the script joinus\_email.rb... from which I am building the emails and delivering them

joinus\_email.rb require 'action\_mailer' require 'mail' ... def send\_email\_back\_to\_sender(..) &nbsp;&nbsp;&nbsp;mail = Notifier.joinus\_email(..) &nbsp;&nbsp;&nbsp;mail.deliver end

any clue welcome ..

---

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [March 17, 2011, 5:34pm UTC](https://discuss.rubyonrails.org/t/x-files-strange-script-behaves-differently-when-running-as-cron-task/57958/2 "2011-03-17T17:34:59Z")

</div>

First clue .. running in the console ... no error .. but when running the script as a cron task, I receive a message from the cron daemon :

/usr/local/rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.5/lib/ action\_view/template/handlers/erb.rb:129:in `valid\_encoding': Your template was not saved as valid US-ASCII. Please either specify US- ASCII as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template: (ActionView::Template::Error)

# encoding: \<name of correct encoding\>.

now what should I do with it ? any complementary clue ?
