# Script runs fine alone but not when called by cron (EPIPE)

**URL:** <https://www.ruby-forum.com/t/script-runs-fine-alone-but-not-when-called-by-cron-epipe/150694>\
**Category:** Ruby\
**Created:** [October 11, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/script-runs-fine-alone-but-not-when-called-by-cron-epipe/150694 "2008-10-11T17:54:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![otto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@otto](https://www.ruby-forum.com/u/otto)\
**Post date:** [October 11, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/script-runs-fine-alone-but-not-when-called-by-cron-epipe/150694/1 "2008-10-11T17:54:43Z")

</div>

Hey, I’m still learning ruby (first week) and I’m having problem with a  
script that sends an e-mail.  
The script (~/teste\_email.rb) runs fine when I call it, but raises and  
exception when ran as a cron task.

## This is the stack trace:

## `write': Broken pipe (Errno::EPIPE) from /usr/lib/ruby/1.8/net/protocol.rb:139:in `\<\<’ from /usr/lib/ruby/1.8/net/protocol.rb:139:in `rbuf_consume' from /usr/lib/ruby/1.8/net/protocol.rb:118:in `readuntil’ from /usr/lib/ruby/1.8/net/protocol.rb:126:in `readline' from /usr/lib/ruby/1.8/net/smtp.rb:664:in `recv\_response’ from /usr/lib/ruby/1.8/net/smtp.rb:551:in `send0' from /usr/lib/ruby/1.8/net/smtp.rb:686:in `critical’ from /usr/lib/ruby/1.8/net/smtp.rb:548:in `send0' ... 7 levels... from /var/lib/gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:414:in `deliver’ from /home/otto/send\_gmail.rb:60:in `send_gmail' from /home/otto/teste_mail.rb:5:in `envia\_email’ from /home/otto/teste\_mail.rb:8

I got send\_gmail.rb from this website:

> **[Sending GMail from a Standalone Ruby Script](http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html)**
>
> As part of my rails application, I need to send emails from a stand alone ruby script. For example, the back end of my rails application is...

Why does it run fine when I call it myself and how do I make it run ok  
from cron?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![otto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@otto](https://www.ruby-forum.com/u/otto)\
**Post date:** [October 13, 2008, 10:54am UTC](https://www.ruby-forum.com/t/script-runs-fine-alone-but-not-when-called-by-cron-epipe/150694/2 "2008-10-13T10:54:39Z")

</div>

2008/10/11 Otto \_\_ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ## from /usr/lib/ruby/1.8/net/protocol.rb:118:in `readuntil' from /home/otto/teste_mail.rb:5:in `envia\_email’ from /home/otto/teste\_mail.rb:8
> 
> I got send\_gmail.rb from this website:  
> [Coding Frenzy: Sending GMail from a Standalone Ruby Script](http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html)
> 
> Why does it run fine when I call it myself and how do I make it run ok  
> from cron?

You do not give near as much detail as needed to properly answer your  
question. Though chances are that the reason lies in different  
environments. Things to look for are PATH and LD\_LIBRARY\_PATH.

Cheers

robert
