I have a fresh install of Ubuntu 12.04.1 LTS an a number of servers.
I have not added any cron jobs or edited my crontab on those servers, however, at around the same time for each machine, I get a 75% CPU spike and the following info in my syslog at the time of the spike:
CRON[8380]: (CRON) info (No MTA installed, discarding output)
I have mono-complete installed and am running a service stack webserver.
What is the best way for me to stop this from happening? I would like to be able to remove the CPU spike.
Linux uses mail for sending notifications to the user. Most Linux distributions have a mail service including an MTA (Mail Transfer Agent) installed. Ubuntu doesn't though.
You can install a mail service, postfix for example, to solve this problem.
Or you can ignore it. I don't think the inability of cron to send messages has anything to do with the CPU spike (that's linked to the underlying job that cron is running). It might be safest to install an MTA and then read through the messages (
mutt
is a good system mail reader).This happens because your cron jobs are producing output and then the cron daemon tries to email that output to you (i.e. root). If you don't need that output, the easiest way to solve this is to discard it at the crontab:
and add
>/dev/null 2>&1
to every job:In my case, the message was hinting at a permissions problem with the bash script, but I couldn't see it until I installed an MTA.
As suggested I ran:
I chose "Local" during setup and after running the cron job again:
In my case I replaced
with "root".
I was then able to see the error output related to permissions.
As stated in an earlier answer, this happens because your cron jobs are producing output, and then the cron daemon tries to email that output to you. If you don’t want to (or can’t) install an MTA, but you want to see the output, you can redirect the output of the cron job to a log file. Edit your crontab file with
(use
sudo
if the issue is with root’s crontab) and add>> /some/log/file 2>&1
after every command, like this:(
>> /some/log/file
sends the standard output to the named file, appending to any existing content, and2>&1
sends the error messages to the same place.)If there are multiple commands on a line, separated by
;
,&
,&&
or||
, you should do the above for each command, like this:or group them, like this:
If the command line ends with
&
, insert the redirection after the command but before the&
. If there are commands separated by|
(a pipeline), the simple solution is to group them:but see also the last paragraph, below.
If you want to ignore stdout and capture only stderr, use
> /dev/null 2>> /some/log/file
instead. Put the log file wherever you want — your home directory,/var/log
, or even/tmp
if you’re sure you won’t need to keep it.Then look at the log file after the job runs.
If you find a mangled mess of interlaced messages, it may be that the program(s) are writing stdout and stderr concurrently with poor coordination. In that case, try writing them to separate files with
>> /some/log/file1 2>> /some/log/file2
. You may need to do something similar with pipelines:(It’s probably also best to use separate files for commands separated by
&
.)This is an old question but there is an additional answer that is useful in some circumstances.
Pipe the output of your cron command through
logger
so they end up in the syslog.It's slightly easier than installing postfix, and it puts this output into syslog alongside your other logs. This command will capture stdout AND stderr so you won't see the
No MTA installed
message and you'll see all your output in the syslog.Example cron entry:
You can view logs with your tag
mycmd
using:In crontab add this as first line:
This will prevent cron from trying to send an e-mail.
If you don't want to install an MTA (which I currently have no need for) you can pipe the results of the cron job to a log file.
then with your cron job would look like this.
then you can just tail the log and see what happened
This is what I have been doing on any server that I see that message in syslog
One side effect of adding
/dev/null 2>&1
to the cron job command, is that it will discard bothSTDERR
andSTDOUT
(Standard Error as well as Output). This works fine if you don't want any emails from cron. But if you want your errors to be emailed to you, use>/dev/null
instead. Read this blog post for more explanation.You'll still need to install an MTA (mail transfer agent) to send the error emails though. Postfix is simple enough to install with:
sudo apt-get install postfix
You can set
MAILTO=””
variable at the start of yourcrontab
file. This will also disable email alert. Edit/Open your cron jobs:At the top of the file, enter:
https://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/
At first, install
postfix
, that can resolve the problemIf Ubuntu, you can edit the
crontab
fileAttention,edit the top file,not any code in the first line,and enter
When
cron
executes any task,you will get an email