I have set up a backup script to back up world data on my Minecraft server hourly using cron, but because the worlds being constantly edited by players, tar was telling me that files changed while they were read. I added --ignore-command-error to the tar in the script and that suppresses any errors when I run it manually, however cron still sends a mail message saying that files were changed while being read, and ends up flooding my mail because it's run once an hour. Anyone know how to fix this? This is the script:

filename=$(date +%Y-%m-%d)
cd /home/minecraft/Server/
for world in survival survival_nether survival_the_end creative superflat
if [ ! -d "/home/minecraft/backups/$world" ]; then
mkdir /home/minecraft/backups/$world
find /home/minecraft/backups/$world -mtime +1 -delete
tar --ignore-command-error -c $world/ | nice -n 10 pigz -9 > /home/minecraft/backups/$world/$filename.tar.gz

4 Answers 4


Cron will attempt to send an email with any output that may have occurred when the command was run. From cron's man page:

When executing commands, any output is mailed to the owner of the crontab (or to the user specified in the MAILTO environment variable in the crontab, if such exists). Any job output can also be sent to syslog by using the -s option.

So to disable it for a specific crontab entry just capture all of the commands output and either direct it to a file or to /dev/null.

30 * * * * notBraiamsBackup.sh >/dev/null 2>&1
  • 2
    D: using my example!
    – Braiam
    Commented Jul 25, 2013 at 1:07
  • @Braiam - sorry I was feeling lazy and didn't feel like typing it up. I would've typed the same thing anyway 8-).
    – slm
    Commented Jul 25, 2013 at 1:12
  • @Braiam - is that better? 8-).
    – slm
    Commented Jul 25, 2013 at 1:14
  • Works great, exactly what I was looking for.
    – Carter
    Commented Jul 25, 2013 at 6:33
  • Note that in my CentOS 7, with crontab not cron, -s means selinux context.....
    – WesternGun
    Commented Jan 9, 2018 at 17:18

Instead of piping everything to /dev/null (which may leave you without a clue of what happened if something goes wrong), you can pipe your scripts to log files like this:

30 * * * * backup.sh > ~/logs/backup.log

And to stop getting mails, just set the MAILTO variable to an empty string at the beginning of your crontab file:

  • 2
    I'd rather write 30 * * * * backup.sh >> ~/logs/backup.log 2>&1
    – ermannob
    Commented Mar 21, 2020 at 21:38
  • I have a lot of crontabs, and some commands are very long. So I think this is the nicer and command-shorter way.
    – Youran
    Commented Nov 23, 2021 at 9:02

If you don't want mails for an specific cron task, you can simply add >/dev/null 2>&1 at the end of the line:

30 * * * * backup.sh >/dev/null 2>&1
  • 1
    I choose this way: you lost track of everything, but neatly.
    – WesternGun
    Commented Jan 9, 2018 at 17:09

You should add the following to your gnu tar command: --warning=no-file-changed

That will suppress all the "%s: file changed as we read it" messages. And by using this solution (and not redirecting everything to /dev/null), you will still be able to get error messages when stuff really goes wrong..

With the --warning flag you can enable and disable a lot of different messages that tar prints. Here's the relevant part of the manual with all the keywords you can use: https://www.gnu.org/software/tar/manual/html_section/tar_27.html.

Note: by adding "no-" in front of a keyword, the message will be suppressed.

You must log in to answer this question.

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