Jump to content

CRON Job - Weird Email


doni49

Recommended Posts

This is one of those questions that could fall under one of several categories.  So I'm not positive which forum to post this in but here goes....

 

I use a hosting service with CPanel access.  I have a PHP script set up to run via CRON.

 

My understanding is that if the PHP script has no output (or any error messages) then the CRON daemon won't send an email message.  If there is any output--if the script uses the print function for instance or if there is an error--then the CRON daemon will send an email to the admin.

 

This is the email message that I've been receiving from the CRON daemon:

X-Powered-By: PHP/5.2.4

Content-type: text/html

 

Yes--that's the ENTIRE message body.

 

I checked the script there are NO print/echo statements (I even used the editor's find option to look for it in case I was just overlooking it).

 

Anyone have any thoughts?

Link to comment
Share on other sites

Firstly, it will send an email if you have one entered, no matter what else happens.  It will not email you the results of the cron.  You should look at some other page to see that.  If you don't want to receive an email put :blackhole: in the email box.

 

Secondly, in order to receive an email from a cron you should setup a mail() function in the script that sends you the results of the script.

Link to comment
Share on other sites

I'm sorry but that just doesn't fit with the experience I've had.  I don't know--maybe I've got something going on that's strange.

 

For the past couple of years, I've had a cron job that runs every five minutes.  The only time it sends an email message is when it had trouble and gives an error message.

 

Also when I was developing my scripts, I was able to print a variable just like I would if I were browsing to my script.  I'd wait a few minutes for my script to run and the email would arrive showing me the variables.

 

Based on what you described, I'd receive nearly 300 messages EVERY day--even if there was no problem.  That wouldn't make sense.  And it wouldn't make sense to send all cron messages to the black hole either--then you wouldn't know if there was a problem.

 

The only issue I'm having now is why in the world is it sending messages that look like this all of a sudden.

 

Link to comment
Share on other sites

Ok found it.

 

The -q flag suppresses HTTP header output. As long as your script itself does not send anything to stdout, -q will prevent cron from sending you an email every time the script runs. For example, print and echo send to stdout. Avoid using these functions if you want to prevent cron from sending you email.

 

http://www.modwest.com/help/kb5-125.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.