regexp matches when run from console, but not when run from cron

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
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.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
so I was mistaken and /.*/.match("myrandomstring") does actually return a match when run from cron. But there must be something about my regex, even though I did simplify it, that is causing a problem under cron.

I'm not going to paste the raw script, just because it's a really really long regex and it's checking against data from a text file that is hundreds of lines long. I'll try tweaking and testing my regex some more and try to find out just what it is that I add to the expression that is causing the funkiness and then post that.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Ok so after doing some more micro testing, I found the part that was not matching, but it didn't really make any sense, so I happened to think to look at the text being matched against. This text is output from a third-party program that gets run as part of the script, and the regex is a match against the date and time. So for example the regex might look like this:
/08\/20\/2009 06:3[0-9]:[0-9][0-9] PM .+/

and I thought it would be matching against text that looks like this:
"08/20/2009 06:30:00 PM loglogloglogloglog"

But apparently when run from cron, the text doesn't look like that. It looks like this:
"08/20/09 18:30:00 loglogloglogloglog"

The year changed from 4 to 2 digits and the time changed from 12-hour to 24-hour. So there must be something in about the environment that is telling this third-party program how to render the date and time format that is being set in root and other user's environment, but not in root's cron environment. I guess this isn't really a programming error in that case, but if anyone knows how I can set cron's environment properly, or maybe even set it up within the script, before the third-party program is called, I would love to hear it.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Ok, it looks like the problem is with locale settings. Users run under the en_US.UTF-8 locale, but Cron runs under the POSIX locale. Luckily, this third-party program has a command line option to set the locale it runs with, so I can probably fix this with that.