Problem with crontab and script/runner

Hi guys, I’m trying to run some process in backgroung each minute using
script/runner.

To do this I use crontab-e and I edit the crontab. This is the line i
wrote:

*/1 * * * * /usr/local/bin/ruby /Users/jose/mimandote.com/script/runner
‘Usuario.usuario_del_dia’

The console says me taht I have new mail in /var/mail/jose. the mail say
this:

From [email protected] Tue Apr 21 10:34:00 2009
Return-Path: [email protected]
X-Original-To: jose
Delivered-To: [email protected]
Received: by Jose.local (Postfix, from userid 503)
id 8E2C853DAC4; Tue, 21 Apr 2009 10:34:00 +0200 (CEST)
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron [email protected] /usr/local/bin/ruby
/Users/jose/mimandote.com/script/runner ‘Usuario.usuario_del_dia’
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=jose>
X-Cron-Env: <USER=jose>
X-Cron-Env: <HOME=/Users/jose>
Message-Id: [email protected]
Date: Tue, 21 Apr 2009 10:34:00 +0200 (CEST)

/bin/sh: /usr/local/bin/ruby: No such file or directory

Somebody can help me to solve this error?

On Apr 21, 9:37 am, Jose vicente Ribera pellicer <rails-mailing-
[email protected]> wrote:

/bin/sh: /usr/local/bin/ruby: No such file or directory

Somebody can help me to solve this error?

At the risk of sounding completely stupid, where is your ruby
interpreter ?

Brandon O. wrote:

Hi,

Ruby isn’t in /usr/local/bin/ruby. Run `which ruby’ to see where it is.

You shouldn’t need to have that path to ruby though before calling
script/runner, because it looks like it already has a shebang line.

Brandon

Hi, ruby is in /usr/bin/ruby :frowning:

Now this is my line in crontab:

*/1 * * * * /usr/bin/ruby /Users/jose/mimandote.com/script/runner
‘Usuario.usuario_del_dia’

The problem is that since i change /usr/local/bin/ruby to /usr/bin/ruby
i don’t recive any mail. This would say thet it runs good? (i say it
because my application doesm’t work and i don’t know if is by cron or by
the programation of the model method).

I tried with this:

*/1 * * * * /Users/jose/mimandote.com/script/runner
‘Usuario.usuario_del_dia’

with the same result :frowning:

Hi,

Ruby isn’t in /usr/local/bin/ruby. Run `which ruby’ to see where it is.

You shouldn’t need to have that path to ruby though before calling
script/runner, because it looks like it already has a shebang line.

Brandon

Sometimes you should test the file which is executed or not.
So I suggest you can write some code in the script to show whether it
work or not, such as
date >> ~/test.txt
After testing it ,you can permit the situation.

On Apr 21, 5:12 pm, Jose vicente Ribera pellicer <rails-mailing-

*/1 * * * * /Users/jose/mimandote.com/script/runner
‘Usuario.usuario_del_dia’

with the same result :frowning:

Have you tried running it directly to see if it works or not?

If it’s not giving any errors, then the script is probably running.

Brandon

Solved, the code it wasn’t the problem

Wang P. wrote:

Sometimes you should test the file which is executed or not.
So I suggest you can write some code in the script to show whether it
work or not, such as
date >> ~/test.txt
After testing it ,you can permit the situation.

On Apr 21, 5:12�pm, Jose vicente Ribera pellicer <rails-mailing-

I try with this:

  •   *       *       *       *       echo 
    

“hola”>>/Users/jose/prueba.txt

and it works perfectly.


This is my code…

crontab:

  •   */6       *       *       *       /opt/local/bin/ruby
    

/Users/jose/mimandote.com/script/runner ‘Usuario.new_usr_dia’

In my aplication

In usuario.rb -->Selects the new user of the day

def self.new_usr_dia
cambiado = false
Usuario.all(:conditions => “usuario_del_dia is NULL”, :order =>
“posicion_ranking”, :limit => 200).each do |usuario|
if cambiado == false and usuario.avatar.existe? # El usuario del
dia tiene que tener avatar
usuario.update_attribute(‘usuario_del_dia’,Time.now.to_s(:db))
cambiado = true
end
end
‘UPDATE usuarios SET usuario_del_dia = NULL’.lanza_sql if
cambiado == false
end


In avatar.rb:

The constant DIRECTORIO:

DIRECTORIO = File.join(“public”, “images”, “avatar”)
(I change it to this -->DIRECTORIO =
File.join(Rails.public_path, “images”, “avatar”). This error doesn´t
appears now:

/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.2/lib/commands/runner.rb:47:
/Users/jose/mimandote.com/app/models/avatar.rb:21:in `mkdir’: No such
file or directory - public/images/avatar (Errno::ENOENT)

But the day usuary doesn’t change :frowning:

Some methods:

def initialize(usuario, imagen=nil) #It creates the directory if
doesn`t exists
@usuario = usuario
@imagen = imagen
Dir.mkdir(DIRECTORIO) unless File.directory?(DIRECTORIO)
end

def existe?
logger.debug “AVATAR.RB(existe?): directorio #{DIRECTORIO} - todo
#{File.join(DIRECTORIO, nombre_archivo)}”
File.exists?(File.join(DIRECTORIO, nombre_archivo))
end


Read

It’s very strange for me that before I tried to run in background this
method it runs perfecly running it from application’s control zone. I
only do this from my controller

def accion_control

Usuario.new_usr_dia if params[:accion] == ‘new-usr-dia’

end

PD.
Sorry…because i know my enlish is not the best.
Thanks a lot!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs