# ./script/runner in crontab -e gives "Mysql:Error"

**URL:** <https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317>\
**Category:** Rails\
**Created:** [February 12, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317 "2007-02-12T16:48:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 12, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/1 "2007-02-12T16:48:44Z")

</div>

```
 Hi ,
     I have no freaking clue what to do with the ./script/runner.
     I wanna send emails by using ./script/runner
     such that i use crontab for it .................

```

1. 

```
 I tried setting out the varible of mysql
          "SET @@NET_READ_TIMEOUT=400;" as per
           http://bugs.mysql.com/bug.php?id=1370)
 But no use i still get the same error.

```

2. 

```
 I'm using lightpd web server.
 Does ./script/runner has anything to do with webserver
 if yes plz tell me how to use ./script/runner with lighttpd

```

3. I dont knw y validates\_captcha error is coming in the log …  
I’ve validates\_captcha rule in user model but how does that cause an  
error.  
or can i just ignore this error???

4. Are there any alternatives ( I heard BackgroundDRB )  
What is latest stable production release for BackgroundDRB …  
Does it do the CRON functionality as well… or  
still needs to plug to crontab…

------------------------ THis is model method i’m using ------------

class Pop \< ActiveRecord::Base

def self.get\_test\_emails\_count  
return Pop.find\_by\_sql([‘select count(p\_user\_id),p\_user\_id from  
pops group by p\_user\_id having count(\*) \> 3’])  
end

def self.test\_emails

@evalsd = Pop.get\_test\_emails\_count

for eval in @evalsd

@user = User.find\_by\_sql([‘select \* from users where id =  
?’,eval.p\_user\_id])

```
UserNotify.deliver_test_emails(@user)

```

end

end

## ---------------------------------------Development.log

ERROR: Could not load RMagick. CAPTCHA image challenge not available.  
(validates\_captcha)

Pop Load (0.000000) Mysql::Error: Lost connection to MySQL server  
during query: select count(p\_id),p\_id from pops group by p\_id having  
count(\*) \> 3

ERROR: Could not load RMagick. CAPTCHA image challenge not available.  
(validates\_captcha)

Pop Load (0.000000) Mysql::Error: Lost connection to MySQL server  
during query: select count(p\_id),p\_id from pops group by p\_id having  
count(\*) \> 3

---------------------my crontab -e is ------------------------------

\*/1 \* \* \* \* ruby /home/jodiks/workspace/govantra/script/runner -e  
development “Pop.test\_emails”

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 12, 2007, 7:03pm UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/2 "2007-02-12T19:03:42Z")

</div>

Have you tried running that job from the command-line, as the user  
whose crontab the job is executed?

If that works, it has to be an environmental issue. For example, if  
you’re using Gentoo Linux, interactive shells will have RUBYOPT=-  
rauto\_gem in the environment, which causes rubygems to be required  
automatically, for any ruby script. However, that environment  
variable isn’t set in a cron job.

Good luck.

Ciao,  
Sheldon.

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 12, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/3 "2007-02-12T19:53:51Z")

</div>

Ashwin,

If you want Cron functionality for Rails, then you should look at

[http://rails.co.za/articles/2006/06/03/using-railscron](http://rails.co.za/articles/2006/06/03/using-railscron)

We are using Rails Cron successfully in Ajuby (  
[http://ajuby.openapp.org](http://ajuby.openapp.org))  
toolkit, as our scheduler (on which we are running Feed aggregation and  
Feed  
notification delivery jobs).

Hope that helps

-Rajesh

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 12, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/4 "2007-02-12T20:42:01Z")

</div>

In direct answer to your question, you should be able to use script/  
runner from cron. Here’s how I do it:

1. log in as the user who owns the crontab
2. cd /to/someplace/other/than/your/rails/directory
3. /full/path/to/rails/root/script/runner -e production “Model.method”

If (3) works as expected, then simply copy that line into your  
crontab. Note two things: You MUST specify your environment or live  
with the default which is, I believe, development; and you should  
quote the method call.

If it doesn’t work, look at your production.log and your various  
error logs. Don’t look at the Web server logs, as there is no  
interaction with your Web server. You may get a log entry if you have  
invalid database login credentials.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 13, 2007, 6:56am UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/5 "2007-02-13T06:56:14Z")

</div>

Rajesh Shetty wrote:

> Ashwin,
> 
> If you want Cron functionality for Rails, then you should look at
> 
> [http://rails.co.za/articles/2006/06/03/using-railscron](http://rails.co.za/articles/2006/06/03/using-railscron)
> 
> We are using Rails Cron successfully in Ajuby (  
> [http://ajuby.openapp.org](http://ajuby.openapp.org))  
> toolkit, as our scheduler (on which we are running Feed aggregation and  
> Feed  
> notification delivery jobs).
> 
> Hope that helps
> 
> -Rajesh

I’ve already looked at it.  
Its a broken url.  
Can u please tell me check out command for it or download link for l

Regards,  
Ashwin

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 13, 2007, 2:04am UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/6 "2007-02-13T02:04:44Z")

</div>

Couple notes.

1. RailsCron is no longer supported by the author (that’s me!).
2. I wrote daemon\_generator, as the simplest possible background rails  
service. Typically, the example workflow is something like  
“do\_my\_service;sleep 10”. Daemon\_generator provides the startup  
scripts, monitoring, logging, etc. So you don’t get cron-like  
scheduling, but I don’t think that’s what you want anyways.

-Kyle

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 16, 2007, 6:07am UTC](https://www.ruby-forum.com/t/script-runner-in-crontab-e-gives-mysql-error/85317/7 "2007-02-16T06:07:59Z")

</div>

Ashwin Kumar wrote:

> Rajesh Shetty wrote:
> 
> > Ashwin,
> > 
> > If you want Cron functionality for Rails, then you should look at
> > 
> > [http://rails.co.za/articles/2006/06/03/using-railscron](http://rails.co.za/articles/2006/06/03/using-railscron)
> > 
> > We are using Rails Cron successfully in Ajuby (  
> > [http://ajuby.openapp.org](http://ajuby.openapp.org))  
> > toolkit, as our scheduler (on which we are running Feed aggregation and  
> > Feed  
> > notification delivery jobs).
> > 
> > Hope that helps
> > 
> > -Rajesh
> 
> I’ve already looked at it.  
> Its a broken url.  
> Can u please tell me check out command for it or download link for l
> 
> Regards,  
> Ashwin

Ashwin,

Thats interesting with Rails plugins, As Kyle himself said above,  
RailsCron no longer supported , But we still use it in Ajuby toolkit. So  
assuming its not available anymore, and you still wants to use it, I  
would say go ahead and download Ajuby toolkit from  
[http://ajuby.openapp.org](http://ajuby.openapp.org) and once you download this, under  
vendor/plugins you will find rails\_cron and that should solve your  
problem. Thats the only way I can think of for you to get a handle on  
rails\_cron.  
Meanwhile look into backgroundrb [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)  
and looks like lot of people are happily using this as background  
processor. We will be looking into this slowly to move away from  
rails\_cron.
