Docker Community Forums

Share and learn in the Docker community.

Suppress docker-compose progress-information in cronjob


#1

Hi all,
i’ve just build a small shell-script that pauses my docker containers, starts rsync to sync my volumes to my NAS and then unpauses the containers again.

#!/bin/bash
set -e

scriptPath=$(dirname "$(readlink -f "${0}")")

/usr/local/bin/docker-compose -f ${scriptPath}/docker-compose.yml pause
rsync -av --delete --password-file=${scriptPath}/.rsync_pass ${scriptPath} pi@192.168.178.2::NetBackup/raspberrypi/
/usr/local/bin/docker-compose -f ${scriptPath}/docker-compose.yml unpause

This works great.
I run this script each day at 03:00 am through root’s crontab:

0 3 * * * /home/pi/rsync_backup > /dev/null

My problem now is, that albeit i set the standard-output to “dev/null”, i get an email with the following content from the cron-daemon:

Pausing pi_bitwarden_1 …

Pausing pi_node-red_1 …

[1A [2KPausing pi_node-red_1 … [32mdone [0m [1B [2A [2KPausing pi_bitwarden_1 … [32mdone [0m [2BUnpausing pi_node-red_1 …

Unpausing pi_bitwarden_1 …

[1A [2KUnpausing pi_bitwarden_1 … [32mdone [0m [1B [2A [2KUnpausing pi_node-red_1 … [32mdone [0m [2B

I believe this is because, the progress-information goes to stderr instead of stdout :confused:

Is there a way to suppress this progress-information in order to get rid of those mails?

I don’t want to redirect stderr to stdout ( 2>&1), as i still wan’t to be noticed of “real” errors.

Thank you very much for your help!

Best regards

Philipp


#2

Simply adding 2>&1 to the docker-compose commands should work, shouldn’t it?

This would redirect stderr to stdout, so i would get no such mails but would still be informed, if the script produces an error and is therefore is aborted, right?

Like

/usr/local/bin/docker-compose -f ${scriptPath}/docker-compose.yml pause 2>&1
...
/usr/local/bin/docker-compose -f ${scriptPath}/docker-compose.yml unpause 2>&1