[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

syntax errors when job run from cron

Russell Fulton

8/21/2006 12:26:00 AM

Well this is weird! I'm used to odd problems when you run programs from
cron but these are almost invariably to do with file permissions or
stuff in the environment variables not matching the command line
environment.

I'm using ruby 1.8.4 (2005-12-24) [i686-linux] on a RHE 3.0 system.

The program runs fine from command line but gets nonsensical syntax
errors when run from cron.

Any idea where to look for the problem?

Russell

--
Posted via http://www.ruby-....

7 Answers

Daniel Baird

8/21/2006 12:33:00 AM

0

On 8/21/06, Russell Fulton <r.fulton@auckland.ac.nz> wrote:
> Well this is weird! I'm used to odd problems when you run programs from
> cron but these are almost invariably to do with file permissions or
> stuff in the environment variables not matching the command line
> environment.
>
> I'm using ruby 1.8.4 (2005-12-24) [i686-linux] on a RHE 3.0 system.
>
> The program runs fine from command line but gets nonsensical syntax
> errors when run from cron.
>
> Any idea where to look for the problem?

Check your paths, maybe?

--
Daniel Baird
http://tidd... (free, effortless TiddlyWiki hosting)
http://danie... (TiddlyW;nks! :: Whiteboard Koala :: Blog ::
Things That Suck)

Russell Fulton

8/21/2006 1:21:00 AM

0

Daniel Baird wrote:
> On 8/21/06, Russell Fulton <r.fulton@auckland.ac.nz> wrote:
>> Any idea where to look for the problem?
> Check your paths, maybe?

All the ruby files are in the same directory which the job cds into
before invoking the program. I've just added an 'env' to the job to
compare all the environment variables. Should have though of that
before...

Russell

--
Posted via http://www.ruby-....

Ara.T.Howard

8/21/2006 2:14:00 AM

0

James Britt

8/21/2006 3:13:00 AM

0

Russell Fulton wrote:
> Well this is weird! I'm used to odd problems when you run programs from
> cron but these are almost invariably to do with file permissions or
> stuff in the environment variables not matching the command line
> environment.
>
> I'm using ruby 1.8.4 (2005-12-24) [i686-linux] on a RHE 3.0 system.
>
> The program runs fine from command line but gets nonsensical syntax
> errors when run from cron.
>
> Any idea where to look for the problem?

What is the user that actually runs the job in cron?

Are you using absolute paths?

#!/usr/local/bin/ruby

not

#!/usr/bin/env ruby

in the script (since env will differ for different users)?

When run from the CLI are there RUBYOPT values (e.g., rubygems) in the
environment that are not there for cron?


--
James Britt

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://refreshing... - Design, technology, usability

Russell Fulton

8/21/2006 3:47:00 AM

0

James Britt wrote:
> Russell Fulton wrote:
>> Any idea where to look for the problem?
> What is the user that actually runs the job in cron?
>
> Are you using absolute paths?
>
> #!/usr/local/bin/ruby
>
> not
>
> #!/usr/bin/env ruby
>
we are getting close here! I've managed to reproduce the error on the
cli by executing the file directly instead of running ruby <filename>

i.e
selms.rb ... dies
whereas
ruby selms.rb ... works fine.

file starts with:

#! /usr/bin/ruby

[rful011@pateke selms]$ ls -l /usr/bin/ruby
-rwxr-xr-x 1 root root 3548 Oct 5 2005 /usr/bin/ruby

cron job looks like this:

40 * * * * cd /home/rful011/selms; ruby ./selms.rb -M -o
selms -t periodic log.patterns

note that the script is invoked via ruby in the cron job but gives the
same symptoms as the file being executed directly.

Here is the output from the cron job:

SHELL=/bin/sh
MAILTO=irt@auckland.ac.nz
SHEll=/bin/sh
OLDPWD=/home/logowner
USER=logowner
PATH=/usr/bin:/bin
PWD=/home/rful011/selms
SHLVL=1
HOME=/home/logowner
LOGNAME=logowner
_=/usr/bin/env
/selms.rb:55: syntax error
when 'periodic' : Periodic.new( conf, $options[:syntax])
^
/selms.rb:56: syntax error
when 'realtime' :
^

--
Posted via http://www.ruby-....

Ara.T.Howard

8/21/2006 4:17:00 AM

0

Russell Fulton

8/21/2006 4:40:00 AM

0

unknown wrote:
> On Mon, 21 Aug 2006, Russell Fulton wrote:
>
>>>
>> file starts with:
>>
>> #! /usr/bin/ruby
>
> you have 1.8.4 installed in one place, probably /usr/local/bin/ and
> 1.6.8 in

Bugger! you're dead right!

[rful011@pateke selms]$ whereis ruby
ruby: /usr/bin/ruby /usr/lib/ruby /usr/local/bin/ruby
/usr/local/lib/ruby /usr/share/man/man1/ruby.1.gz
[rful011@pateke selms]$ ls -l /usr/local/bin/ruby
-rwxr-xr-x 1 root root 1214420 Jul 24 16:28
/usr/local/bin/ruby

I was using darwin ports on a mac to install FreeRide and aborted it
when I realised it was installing its copy of Ruby. I though I had got
rid of it, but clearly not!

Now I'll figure out why 1.8.4 is generating syntax errors.

Thank you very much!


--
Posted via http://www.ruby-....