mail_wrap_script.sh: secure output log and allow multiple simultaneous instances

This commit is contained in:
Alice Gaudon 2020-01-29 05:19:19 +01:00
parent 38780399db
commit 7c0b8bae26

View File

@ -4,11 +4,16 @@ SCRIPT=$1
shift shift
$SCRIPT "$@" 2>&1 | tee /tmp/backup.log FILE_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)
touch /tmp/$FILE_ID.log
chmod a-rwx,u+r /tmp/$FILE_ID.log
$SCRIPT "$@" 2>&1 | tee /tmp/$FILE_ID.log
ERR=$? ERR=$?
OUTPUT=$(cat /tmp/backup.log) OUTPUT=$(cat /tmp/$FILE_ID.log)
rm /tmp/backup.log rm /tmp/$FILE_ID.log
if [ $ERR -ne 0 ]; then if [ $ERR -ne 0 ]; then
MAILTO=$(cat "$HOME/.admin_mail") MAILTO=$(cat "$HOME/.admin_mail")