The British Caving Association

Any views expressed are not necessarily those of the BCA
It is currently Mon 20 May 2019 11:56

All times are UTC [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun 06 Jan 2019 14:34 
User avatar

Joined: Thu 16 Mar 2006 23:45
Posts: 474
If you have selected CPANEL's setting to send you an email when your CRON jobs execute, and you want to disable this for specific jobs, CPANEL says...

You can have cron send an email everytime it runs a command which produces output. If you do not want an email to be sent for an individual cron job you can redirect the command’s output to /dev/null like this: mycommand >/dev/null 2>&1

That is not the whole truth - although it is repeated through the Internet. The salient point is that an email will be generated if CRON does not know what else to do with the output, so sending STDOUT and STDERR anywhere will suppress email output for that output stream. Thus, for example mycommand >/some_file will generate an email if there is any output on the STDERR stream, and mycommand >/some_file 2>some_error_file will log all output and not send an email.

Note that some commands (e.g. CURL) will produce output on STDERR which is not what the naive user might think of as an "error reports". Thus, if you want STDOUT to send you an email, you might want to redirect STDERR somewhere else, otherwise the two streams will be mixed in your email.

Ive taken to using CRON in the form curl http://somefile?a=1\&b=2 >mylog 2>myerrorlog because that provides an easy way to test the command, via a browser, and then simply log the web page it produces. TOP TIP: Dont forget to to escape any &s in your query string. If you dont do that, your log files will be empty and CRON will send the output by email. (The ampersand is treated as a command terminator and means 'run this command in the background').

For more on > and 2>&1, etc, go to ... tions.html or ... EDIRECTION. The latter is better formatted, so its easier on the eye, but neither are a particularly easy read. But there are loads of people asking about redirection and so Google will point you somewhere helpful, probably.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group