Syntax errors when job run from cron

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

On 8/21/06, Russell F. [email protected] wrote:

Any idea where to look for the problem?
Check your paths, maybe?

Daniel B. wrote:

On 8/21/06, Russell F. [email protected] 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

On Mon, 21 Aug 2006, Russell F. wrote:

Any idea where to look for the problem?

Russell

probably you have two ruby installations and the wrong one is running
your
script.

-a

James B. wrote:

Russell F. 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

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
[email protected]
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’ :
^

Russell F. 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

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 B.

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://refreshingcities.org - Design, technology, usability

unknown wrote:

On Mon, 21 Aug 2006, Russell F. 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!

On Mon, 21 Aug 2006, Russell F. 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
/usr/bin

type

which -a ruby

and

/usr/bin/ruby -v
/usr/local/bin/ruby -v

probably you should change the shebang line in your script. alternately
you
can set the PATH in your crontab like so

PATH=/usr/local/bin:$PATH

regards.

-a