Tuesday, May 30, 2017

Cron emails output even when redirecting to /dev/null 2>&1



The code below should redirect all output to /dev/null however root still receives an email with output from the first command (/usr/bin/svnadmin). Why?



#!/bin/sh
# Dump repo and upload via tarsnap


/usr/bin/svnadmin dump /srv/repos/www | gzip > /srv/repos/backup/www-repo-`date --iso-8601`.gz > /dev/null 2>&1
/usr/local/bin/tarsnap -c -f www-repo-`date --iso-8601` /srv/repos/backup/www-repo-`date --iso-8601`.gz > /dev/null 2>&1

Answer



You have piped the second commands STDOUT and STDERR to /dev/null, and only piped the first command's STDOUT to the second command. So the first command's STDERR is e-mail-ed to you.



You should write



( /usr/bin/svnadmin dump /srv/repos/www | gzip > /srv/repos/backup/www-repo-`date --iso-8601`.gz ) > /dev/null 2>&1


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...