From: Xeno Campanoli Date: 2009-08-20T03:23:53+09:00 Subject: Re: when run from cron, regex NEVER match, always give nil Tim Hunter wrote: > 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. It probably has something to do with the cron not using Bash as the default shell, though why this would affect Ruby, I fail to understand. I ran into this before though. On Debian flavor machines especially a more Bourneshell-shell like minimalist shell is used as the default instead of Bash, and you end up getting it as your shell in at, and I think Cron. Is it possible your regex stuff is somehow getting stuff from a point in the shell that could lose the data if it were not Bash? >> >> 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. > -- They are the flesh. They are the bone. They are the very cornerstone. - Janis Ian