8

I have a cron job that is just running rsync on a particular directory.

When I run the rsync command itself sudo rsync -av --delete /directory1 /directory2, it runs without issue and does exactly as intended.

When the Cron job runs - I see it in /var/log/syslog.1 and it says this (summarized):

Mar  12 11:38:01 ip-xx-xx-xx-xxx CRON[4970]: (root) CMD (rsync --delete /my/directory /backup/directory)
Mar  12 11:38:01 ip-xx-xx-xx-xxx CRON[4970]: (CRON) info (No MTA installed, discarding output)

But the files are not in the backup directory (so it's not completing).

Does that second statement about 'No MTA installed' prevent the completion of the cron job? What is the best way to get that cron job to complete and get rid of the MTA error?

I found this answer but it doesn't say if that prevents the job from finishing.

1
  • Show us your crontab. Show us your script. No MTA installed makes me thing "No Mail Transfer Agent installed", and your cron job is trying to send mail (maybe just by writing to STDERR or STDOUT).
    – waltinator
    Mar 13, 2017 at 21:26

1 Answer 1

9

No, it does not prevent the CRON job from finishing.

Normally, you shouldn't let your CRON job generate output without telling it where to write it. If you do, like in this case, CRON tries to mail it somewhere (also specified in the crontab file). If it doesn't succeed, it discards the output, as it says in the log file, and goes on.

In your case, you don't have a "Message Transfer Agent" installed. This is a generic name for packages, like postfix and ssmtp, that provide a mail command.

I recommend redirecting SYSOUT and SYSERR from the rsync command using > and 2>, respectively. If you're not interested at all, redirect output to /dev/null.

9
  • How would I go about having it print to a log instead of trying to mail it?
    – Hanny
    Mar 13, 2017 at 15:06
  • sudo rsync -av --delete /directory1 /directory2 > /log/file 2> /log/errors. Use full path names to the log files. If you want regular output and errors to end up in the same file, use > /log/file 2>&1 rather than specifying the same file name twice.
    – Jos
    Mar 13, 2017 at 15:07
  • Excellent, thanks. Must be something strange in my cronjob then that's causing them to not actually finish (although I don't see any errors in the logs other than the MTA error); I don't see the 'copied' files.
    – Hanny
    Mar 13, 2017 at 15:16
  • As you are using the -v flag, rsync should report something about numbers of bytes sent/received, transfer speed, etc. That should be at the bottom of the log file. Also, if this is the literal command, rsync will create a directory /directory2/directory1 with the contents of the original directory1.
    – Jos
    Mar 13, 2017 at 15:20
  • It's run daily - so I'm going to set it to report to the logfile and give it a run. From the existing logfiles, it appears to be running, but when I go to the directory where I should find the files, it's empty.
    – Hanny
    Mar 13, 2017 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .