How exactly do you know that your regular expression doesn't match?
It's more likely your program is matching, but that your output is not going
where you expect. Cron output goes to the user. Since you are running this
as root, are you reading root's mail?

Create a ruby program like, cron_test.rb

if /.*/.match("myrandomstring")
  raise "Matched"
else
  raise "No match"
end

and then in your crontab

*/5 * * * * /path/to/ruby /other/path/to/cron_test.rb

wait 10 minutes and then read root's mail.

Ray





On Wed, Aug 19, 2009 at 5:54 PM, James Dinkel <jdinkel / gmail.com> wrote:

> g_f wrote:
> > Like Tim said, it's probably something in the environment. Besides
> > PATH, you could have other environment variables set in your BASH
> > startup that are not set when the default /bin/sh gets started.
> >
> > For apps I have to run from cron, if I need to, I'll write a
> > wrapping .sh script that sets up the environment exactly as I need it.
> > That could include switching to bash/csh/zsh or whatever, or
> > sourcing .login or .profile or manually setting variables. Cron is
> > stupid and does exactly what is said plus whatever (hidden) defaults
> > the system has set up, so figuring it out can be a real task.
> >
> > I wonder if you might have installed some libraries in your own space
> > instead of the system's Ruby space. User permission problems will crop
> > up then and can be a pain to figure out. I'd debug that by logging in
> > as whatever user the cron job runs as, then manually run the script.
> >
> > You don't say whether your job is running out of your own user's cron,
> > or out of root's cron, or via the system's /etc/crontab. For my
> > production code I set up the scripts to be run as root, but that's
> > because I've been doing this so long I've shot off most of my toes and
> > learned the hard lessons about what not to do... I'm sufficiently
> > paranoid so I'm considered a trusted user. :-)
>
> sorry for the silence, I've been swamped today (consultants are here
> doing a networking hardware upgrade).  However, I was incorrent in that
> '/.*/.match("myrandomstring")' does actually return a match when run
> from cron, but my actual regex is a bit more complicated.  My actual
> regex does match when run manually though.
>
> I think I'm going to do a little more testing and cut some parts out of
> the regex to find if maybe there is just a single unit of the expression
> that is the problem.  It's a tedious pain in the rump, though since it
> matches when run manually, I have to make a change, check the time, set
> it to run in a minute from cron, wait for it to run, check the output
> file... very tedious and time-consuming.
>
> This is run by root's cron by the way.  I don't how to do "sourcing
> .login or .profile" but I did try making a wrapper script with a
> /bin/bash hashbang that then just calls the ruby script, and that didn't
> make any difference.
> --
> Posted via http://www.ruby-forum.com/.
>
>