Commit 0cf7da67 authored by Simone Piccardi's avatar Simone Piccardi
Browse files

Gestione dell'output

parent d205e97e
......@@ -54,23 +54,29 @@ ERRLOG=/tmp/fuss-backup-err.log
MESS="Data dump on $(hostname) for $(date +%x)"
# all output go to TMPLOG
exec 6<&1
exec > $TMPLOG 2>&1
# define exit function (sending email)
mail_exit () {
if [ $1 != 0 ]; then
MAILSUBJ="Backup fail on $(hostname) for $(date +%x)"
else
MAILSUBJ="Backup ok on $(hostname) for $(date +%x)"
fi
if [ "$MAILTO" ]; then
DESTINARI="$MAILTO"
if [ -z "$COMMAND" ]; then
if [ $1 != 0 ]; then
MAILSUBJ="Backup fail on $(hostname) for $(date +%x)"
else
MAILSUBJ="Backup ok on $(hostname) for $(date +%x)"
fi
if [ "$MAILTO" ]; then
DESTINARI="$MAILTO"
else
DESTINARI=root
fi
for i in $DESTINARI; do
grep -v "Hexadecimal number" $TMPLOG | mailx -s "$MAILSUBJ" $i
done
else
DESTINARI=root
exec 1<&6 6<&-
cat $TMPLOG
fi
for i in $DESTINARI; do
grep -v "Hexadecimal number" $TMPLOG | mailx -s "$MAILSUBJ" $i
done
exit $1
}
......@@ -157,11 +163,11 @@ if [ "$COMMAND" ]; then
borg mount $DESTINATION $RECOVERDIR
cat $TMPLOG
echo "mounted backup on $RECOVERDIR"
exit 0
RETURN=0
else
cat $TMPLOG
echo "cannot mount repository"
exit 6
RETURN=6
fi
;;
umount)
......@@ -170,17 +176,19 @@ if [ "$COMMAND" ]; then
umount $BASEDIR
cat $TMPLOG
echo "backup recover umounted"
exit 0
RETURN=0
;;
*)
echo "unknown command $COMMAND"
cat $TMPLOG
usage
exit 5
;;
RETURN=5
esac
mail_exit $RETURN
fi
##
## Batch backup execution (when no command is given)
##
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment