Forum: Ruby on Rails Problem with crontab and script/runner

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-04-21 10:37
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 jose@Jose.local  Tue Apr 21 10:34:00 2009
Return-Path: <jose@Jose.local>
X-Original-To: jose
Delivered-To: jose@Jose.local
Received: by Jose.local (Postfix, from userid 503)
        id 8E2C853DAC4; Tue, 21 Apr 2009 10:34:00 +0200 (CEST)
From: jose@Jose.local (Cron Daemon)
To: jose@Jose.local
Subject: Cron <jose@Jose> /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: <20090421083400.8E2C853DAC4@Jose.local>
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?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-21 10:46
(Received via mailing list)
On Apr 21, 9:37 am, Jose vicente Ribera pellicer <rails-mailing-
l...@andreas-s.net> 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 ?
F85bacbbd4814799d4526b3e35a431df?d=identicon&s=25 Brandon Olivares (devbanana)
on 2009-04-21 10:56
(Received via mailing list)
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
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-04-21 11:12
Brandon Olivares 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  :(

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).
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-04-21 11:54
I tried with this:


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

with the same result :(
F85bacbbd4814799d4526b3e35a431df?d=identicon&s=25 Brandon Olivares (devbanana)
on 2009-04-21 12:15
(Received via mailing list)
>
> */1 * * * * /Users/jose/mimandote.com/script/runner
> 'Usuario.usuario_del_dia'
>
> with the same result :(

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
Ae82abddb56f9cc7864d794fa2704dd6?d=identicon&s=25 Wang Pengcheng (Guest)
on 2009-04-22 08:37
(Received via mailing list)
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-
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-04-23 10:51
Wang Pengcheng 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 :(

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!!
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-04-23 13:16
Solved, the code it wasn't the problem
This topic is locked and can not be replied to.