From: Tim Hunter Date: 2009-08-19T10:09:52+09:00 Subject: Re: when run from cron, regex NEVER match, always give nil James Dinkel wrote: > I'm using ruby 1.8.6 on RHEL 5.3. I also had this problem with ruby > 1.8.5 that comes with RHEL. I had hoped the ruby upgrade would fix it > but it didn't. > > Anyway, no regexps will match, even the most blatant matches, when the > script is run from cron. > > A line like '/.*/.match("myrandomstring")' matches just fine when the > script is run from the console, but it returns nil when run from cron. > And that regex should match ANYTHING. > > I'm not sure if this is an issue with ruby or if it is something with > cron, but I really need regex's to work from cron scripts. Help? It's cron. Or rather, it's not cron, or Ruby, but something about the environment that cron sets up to run your script. Think about it. A Ruby program doesn't "know" that it's being run from cron. It just runs. There's nothing in Ruby that says "Oh, I've been invoked from cron, so I need to do things differently." Ruby scripts always do the same thing no matter how they're invoked. Regexps match, or don't match, no matter how you invoke the Ruby script. Therefore something about the environment that is present when cron runs your script is different than you expect. You don't say how you know that the regexp doesn't match. What symptom of failure do you have? 99% of all cron problems are caused by PATH differences. Remember cron uses a different PATH than you have in your personal shell. You may have to specify the full path to Ruby, or something like that. See http://unixgeeks.org/security/newbie/unix/cron-1.html for some more info. -- MagickWand for Ruby - http://magickwand.rubyforge.org/