LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cron output to a file (http://www.linuxquestions.org/questions/linux-general-1/cron-output-to-a-file-293910/)

Temujin_12 02-23-2005 11:33 AM

Cron output to a file
 
How do you tell cron to send the output to a file rather than send an email?

Temujin_12 02-23-2005 11:55 AM

After more research it looks like there is not a way to tell cron to output to a file. Of course you can just modify your commands so that they pipe thier output to a file but my problem is that one of my cron jobs restarts apache and it runs a configtest which outputs "Syntax OK" to the screen regardless of wheither you piped it to a file or not.

Perhaps my question is how can I avoid the "Syntax OK" from being outputted?

I believe this is being outputted by Perl's "configtest" command. I do want the output from "configtest" to output when there is an error. I just don't want the "Syntax OK" message.

homey 02-23-2005 12:45 PM

The message "Syntax OK" seems to be just standard output and not an err message. So, you could redirect standard ouput to a file. Might as well redirect any errors as well. I would put that in the script at the end of your configtest line.

Here's a couple of examples:
ls nofile > test 2>&1 ## this one only has errors
ls /home > test 2>&1 ## this one only shows the result of ls because it has no errors.

ivanatora 02-23-2005 01:23 PM

If you don't want it at all, send it to > /dev/null :)

Temujin_12 02-23-2005 01:27 PM

I tried "ls nofile > test 2>&1" on my local Gentoo machine and it works just fine. But when I try "ls nofile > test 2>&1" on the FreeBSD system, where the cronjob is, it gives me "Ambiguous output redirect." Is the syntax different for "ls nofile > test 2>&1" on a FreeBSD system?

"ls nofile > test 2" works on the FreeBSD system but "Syntax OK" is still outputted to the screen while everything else from the script is piped to the file.

homey 02-23-2005 01:52 PM

Those were only examples, not to put exactly like that in your script.

Here is an example which may be more meaningful to you....

configtest 1> /dev/null


All times are GMT -5. The time now is 07:20 PM.