So I have a script that I debug with a bunch of echo statements. This is run every 3 minutes on my server by cron, and I sometimes leave the echo statements in there. They're not going to a browser, they're just going... anywhere?

This is a vague question I guess, but what happens when there's no end-user or output for an echo statement? Does it hog up memory? Does it just vanish? I'd appreciate any help in understanding this.

Comments

Upvoted for title poetry. :) (And mutual interest, but nevermind that.)

Written by Agor

Yes, I agree with Agor, nice title!

Written by DGM

You get points for title poetry?!! Well, yes, it's much better than some I've seen.

Written by pavium

I'll take what I can get :)

Written by Alex Mcp

Accepted Answer

The answer is yes, and the output is mailed to the account that is running the cron task. You can change this in the crontab file by setting a "MAILTO=accountname" option, like this example cron file:

MAILTO=root

# run a script every hour
01 * * * * root run-parts /etc/cron.hourly
#etc.

Any output from the above cron task would be mailed to the root user. As Mike B posted, you can also simply redirect the output elsewhere on the task line using the > operator:

01 * * * * php testscript.php > /var/log/logfile.log

in which case cron does not see it and does not send an email.

The bottom line is that if you leave some echo statements in a PHP script and set it as a cron job, then you will start getting emails from the cron daemon.

Written by zombat
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki