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-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org Tue Apr 21 10:34:00 2009 Return-Path: <jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org> X-Original-To: jose Delivered-To: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org Received: by Jose.local (Postfix, from userid 503) id 8E2C853DAC4; Tue, 21 Apr 2009 10:34:00 +0200 (CEST) From: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org (Cron Daemon) To: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org 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-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org> 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? -- Posted via http://www.ruby-forum.com/.
On Apr 21, 9:37 am, Jose vicente Ribera pellicer <rails-mailing- l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 ?> -- > Posted viahttp://www.ruby-forum.com/.
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> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Jose vicente Ribera pellicer > Sent: Tuesday, April 21, 2009 4:38 AM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] 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 jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org Tue Apr 21 10:34:00 2009 > Return-Path: <jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org> > X-Original-To: jose > Delivered-To: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org > Received: by Jose.local (Postfix, from userid 503) > id 8E2C853DAC4; Tue, 21 Apr 2009 10:34:00 +0200 (CEST) > From: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org (Cron Daemon) > To: jose-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org > 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-fcf2JQ7/yFus1BDpvl8NfQ@public.gmane.org> > 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? > -- > Posted via http://www.ruby-forum.com/. > >
Jose vicente Ribera pellicer
2009-Apr-21 09:12 UTC
Re: Problem with crontab and script/runner
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. > > BrandonHi, 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). -- Posted via http://www.ruby-forum.com/.
Jose vicente Ribera pellicer
2009-Apr-21 09:54 UTC
Re: Problem with crontab and script/runner
I tried with this: */1 * * * * /Users/jose/mimandote.com/script/runner ''Usuario.usuario_del_dia'' with the same result :( -- Posted via http://www.ruby-forum.com/.
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Jose vicente Ribera pellicer > Sent: Tuesday, April 21, 2009 5:54 AM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Problem with crontab and script/runner > > > I tried with this: > > > */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> -- > Posted via http://www.ruby-forum.com/. > >
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- l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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). > -- > Posted viahttp://www.ruby-forum.com/.
Jose vicente Ribera pellicer
2009-Apr-23 08:51 UTC
Re: Problem with crontab and script/runner
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!! -- Posted via http://www.ruby-forum.com/.