homepage Welcome to WebmasterWorld Guest from 23.20.43.165
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Weird cron job issue - works for one user, but not another
jdbnd




msg:3837434
 3:19 pm on Jan 29, 2009 (gmt 0)

I have a cronjob set up that runs a relatively simple PHP script that evaluates criteria in a local MySQL table and then sends an email to an external address with the results.

Here's the issue. The script runs fine when I type it in as a URL (www.example.com/folder/script.php) - email delivered fine and everything. And as a cronjob, it runs fine too, when it's tested by my webhost's tech support people (it emails them), but it will NOT email me.

I've tried 3 different email addresses, no dice. Not in the inbox, and not in the spam filter. But when the tech support person uses her personal Yahoo email address, it works fine for her.

Huh? Any ideas?

Thanks,
Joe

 

mcavic




msg:3837476
 4:19 pm on Jan 29, 2009 (gmt 0)

It sounds like it's looking for an environment variable that doesn't exist on your account. If you have shell access, you can try running it manually to see if it gives any errors. Does the code use $ENV, $_SERVER, etc?

jdbnd




msg:3837478
 4:25 pm on Jan 29, 2009 (gmt 0)

It does use $_SERVER, but then why would it be able to send to one email address, but not to another? The email address is stored in a variable called $to and the email is sent using mail() - all seems pretty straightforward.

I can run it fine manually, but I just run it from a browser, not the shell.

Joe

mcavic




msg:3837565
 5:50 pm on Jan 29, 2009 (gmt 0)

$_SERVER would be a problem for cron. It's possible that the tech has the $_SERVER variables set in her profile for debugging purposes. In that case, it should work for any address when she runs it, but for you it would only work from the URL.

If that's the problem, you may be able to remove it from the script and hard-code the necessary data. Or, you may be able to use curl or wget to call the URL from cron, which would act the same as calling it from your Web browser.

jdbnd




msg:3837722
 8:24 pm on Jan 29, 2009 (gmt 0)

I checked and I was actually wrong about that. It doesn't use $_SERVER anywhere, just $_POST in a couple of places (for constructing the headers of the email) and uses Curl also, as part of the function involves calling an external website.

Joe

jdbnd




msg:3837732
 8:35 pm on Jan 29, 2009 (gmt 0)

Here's the code itself:

include "../config/config.php";
include "../includes/class.db.php";
include "../includes/functions.php";

$db = new db();
$data = $db->get_all_rows('lead_buyer="ed" AND featured_school="1"', 'aa_institution');
$errors = '';

foreach ($data as $school) {
$page = visit($school['form_url']);
if ($page == "NO") {
$errors = $errors.$school['institution_name'].' is blah blah blah';
}
}

if ($errors == '') {
exit();
} else {
$to = 'joe@example.com';
$subj = "blah blah blah";
$mess = "";
$mess = $errors;
$headers = "";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = "content-type:text/html; charset=UTF-8 \r\n";
$headers = "From: ".$_POST['email']."\r\n";
$headers = "To: ".$to."\r\n";
$headers = "Return-Path: ".$_POST['email'];

$to_return = "-f".$to;
mail($to, $subj, $mess, $headers, "-f".$to);
}

exit();

mcavic




msg:3837779
 10:00 pm on Jan 29, 2009 (gmt 0)

$_POST won't exist unless you're calling it from a POST form. I'm not sure if that would cause the mail to fail, but it can't be good. When calling from cron, you should hard-code the From address.

jdbnd




msg:3837793
 10:15 pm on Jan 29, 2009 (gmt 0)

Did that, still no dice...

I can't figure out why a cronjob would care which email address it was sending results to - since it apparently works fine when the tech puts her own email address in - she waited for it to execute at the schedule time, and it executed, and sent her an email.

If it matters, the web host console I'm using is DirectAdmin.

Argh.

Joe

mcavic




msg:3837802
 10:26 pm on Jan 29, 2009 (gmt 0)

What's the command line that you're using to call the script under cron?

jdbnd




msg:3837804
 10:28 pm on Jan 29, 2009 (gmt 0)

/usr/local/bin/php -f /home/account/domains/example.com/public_html/actions/walker.php

"account" and "example" are plugs - they're called different things in the real command line.

Joe

mcavic




msg:3837805
 10:32 pm on Jan 29, 2009 (gmt 0)

Try

cd /home/account/domains/example.com/public_html/actions; /usr/local/bin/php walker.php

Otherwise the includes wouldn't be able to find their files. The tech could be running it this way.

jdbnd




msg:3837809
 10:40 pm on Jan 29, 2009 (gmt 0)

You rule. I wish you all good things.

Joe

mcavic




msg:3837814
 10:42 pm on Jan 29, 2009 (gmt 0)

Glad to help!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved