"(CRON) info (No MTA installed, discarding output)" error in the syslog

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.

Asked By: sungiant

||

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.

sudo apt-get install postfix

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).

Answered By: martin

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:

sudo crontab -e

and add >/dev/null 2>&1 to every job:

* * * * * yourCommand >/dev/null 2>&1
Answered By: rob

One side effect of adding /dev/null 2>&1 to the cron job command, is that it will discard both STDERR and STDOUT (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

Answered By: paneer_tikka

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:

sudo aptitude install postfix

I chose “Local” during setup and after running the cron job again:

sudo tail -f /var/mail/<user>

In my case I replaced

<user>

with “root”.

I was then able to see the error output related to permissions.

Answered By: Martin Carstens

In crontab add this as first line:

MAILTO=""

This will prevent cron from trying to send an e-mail.

Answered By: 88weighed

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.

sudo crontab -e

then with your cron job would look like this.

0 3 * * * /cmd/to/run >> /var/log/somelogfile.log

then you can just tail the log and see what happened

sudo tail -f -n 50 /var/log/somelogfile.log

This is what I have been doing on any server that I see that message in syslog

Answered By: Andrew MacNaughton

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

crontab -e

(use sudo if the issue is with root’s crontab)
and add >> /some/log/file 2>&1
after every command, like this:

0 3 * * * cmd  >> /some/log/file 2>&1

(>> /some/log/file
sends the standard output to the named file,
appending to any existing content,
and 2>&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:

0 3 * * * cmd1  >> /some/log/file 2>&1;  cmd2  >> /some/log/file 2>&1

or group them, like this:

0 3 * * * (cmd1;  cmd2)  >> /some/log/file 2>&1

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:

0 3 * * * (cmd1  |  cmd2)  >> /some/log/file 2>&1

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:

0 3 * * * cmd1  2>> /some/log/filecmd1err  |  cmd2  >> /some/log/filecmd2 2>&1

(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:

0 3 * * * (cmd1;  cmd2) 2>&1 | logger -t mycmd

You can view logs with your tag mycmd using:

grep 'mycmd' /var/log/syslog
Answered By: Michael Hunter

You can set MAILTO=”” variable at the start of your crontab file. This will also disable email alert. Edit/Open your cron jobs:

$ crontab -e

At the top of the file, enter:

MAILTO=""

https://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/

Answered By: Damien C
  1. At first, install postfix, that can resolve the problem

    sudo apt-get install postfix
    
  2. If Ubuntu, you can edit the crontab file

    sudo vim /etc/crontab
    
  3. Attention,edit the top file,not any code in the first line,and enter

    MAILTO=root // current system user
    
  4. When cron executes any task,you will get an email

    mail
    
Answered By: shahramlu

I had this problem using the Kitematic Docker tools.
Go to the magento container and click on exe.

Then run

apt-get update

This is if you’re trying to get magento run on kitematic. The log will show this error on the virtual machine:

need update.

Sorry if this got you lost, but that’s how it works. You keep getting lost, but just read about it and the pieces will come together one day. Be patient.

Answered By: Ali Bayati

I had the problem today, but on containers in an isolated network, so no internet… And I was not able to add file redirect on each job since they were automatically deployed…

I found this quick&dirty hack, but it works!

# echo -e '#!/bin/bashnlogger -t fake-sendmail' > /usr/sbin/sendmail
# chmod a+x /usr/sbin/sendmail

If it can help someone…

Answered By: Elektordi

first off all, install postfix

sudo apt-get install postfix

then add logs to you crontab command :

0 0 * * * /home/test.sh /var/log/test.log 2>&1

pay attention to your script requirements, if your script need to run on bash change your command like this.

0 0 * * * /bin/bash -c "/home/test.sh" > /var/log/test.log 2>&1

Answered By: hassanzadeh.sd

On Debian, exim4-daemon-light works for me:

apt install exim4-daemon-light

Background information: It was installed on the machine but got replaced when I installed ssmtp manually. After uninstalling ssmtp, the error occured because the system had no package which provided mail-transport-agent.

Answered By: Nicolas Peifer
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.