Frage

I know this has been asked many times, but I can find a suitable answer in my case.

I croned a backup script using rsync and would like to see all output, errors or not, from the all script commands. I must write the command inside the script itself, and do not want to see output in my shell. I have been trying with no success. Below part of the script.

#!/bin/bash
.....
BKLOG=/mnt/backup_error_$now.txt
# Log everything to log file
# something like
exec 2>&1 | tee $BKLOG 
# OR
exec &> $BKLOG

I have been adding at the script beginig all kinds of exec | tee $BKLOG with adding &>, 2>&1at various part of the command line, but all failed. I either get an empty log file or incomplete. I need to see on log file what rsync has done, and the error if script failed before syncing.

Thank you for help. My shell is zsh, so any solution in zsh is welcomed.

War es hilfreich?

Lösung

To redirect all the stdout/stderr to a file place this line on top of your script:

BKLOG=/mnt/backup_error_$now.txt
exec &> "$BKLOG"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top