2019-12-18 21:56:16 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SCRIPT=$1
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
2020-01-29 05:19:19 +01:00
|
|
|
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
|
2020-01-29 04:00:04 +01:00
|
|
|
ERR=$?
|
2019-12-18 21:56:16 +01:00
|
|
|
|
2020-01-29 05:19:19 +01:00
|
|
|
OUTPUT=$(cat /tmp/$FILE_ID.log)
|
|
|
|
rm /tmp/$FILE_ID.log
|
2020-01-29 04:00:04 +01:00
|
|
|
|
|
|
|
if [ $ERR -ne 0 ]; then
|
2019-12-18 21:56:16 +01:00
|
|
|
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
|
|
|
|
fi
|