server-scripts/mail_wrap_script.sh

18 lines
315 B
Bash
Executable File

#!/bin/bash
SCRIPT=$1
shift
OUTPUT=$($SCRIPT "$@" 2>&1)
if [ $? -ne 0 ]; then
MAILTO=$(cat "$HOME/.admin_mail")
echo "Sending error mail"
echo -e "An error occured during the execution of $SCRIPT.\n\n$OUTPUT" | mailx -s "$(hostname) $SCRIPT failure" "$MAILTO"
echo "Sent"
exit 1
else
echo -e "$OUTPUT"
fi