Improve mailing scripts and workflow
This commit is contained in:
parent
ea4e5d0a01
commit
37ab936f2e
8
mail.sh
Executable file
8
mail.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
MAILFROM=$(cat ~/.host_mail)
|
||||||
|
MAILTO=$(cat "$HOME/.admin_mail")
|
||||||
|
|
||||||
|
SUBJECT=$1
|
||||||
|
|
||||||
|
cat | mailx -s "$SUBJECT" -r "$MAILFROM" "$MAILTO"
|
@ -1,24 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SCRIPT=$1
|
SCRIPT=$1
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
FILE_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)
|
FILE_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)
|
||||||
|
|
||||||
touch /tmp/$FILE_ID.log
|
touch /tmp/$FILE_ID.log
|
||||||
chmod a-rwx,u+r /tmp/$FILE_ID.log
|
chmod a-rwx,u+r /tmp/$FILE_ID.log
|
||||||
|
|
||||||
$SCRIPT "$@" 2>&1 | tee /tmp/$FILE_ID.log
|
$SCRIPT "$@" 2>&1 | tee /tmp/$FILE_ID.log
|
||||||
ERR=${PIPESTATUS[0]}
|
ERR=${PIPESTATUS[0]}
|
||||||
|
|
||||||
OUTPUT=$(cat /tmp/$FILE_ID.log)
|
OUTPUT=$(cat /tmp/$FILE_ID.log)
|
||||||
rm /tmp/$FILE_ID.log
|
rm /tmp/$FILE_ID.log
|
||||||
|
|
||||||
if [ $ERR -ne 0 ]; then
|
if [ $ERR -ne 0 ]; then
|
||||||
MAILTO=$(cat "$HOME/.admin_mail")
|
|
||||||
echo "Sending error mail"
|
echo "Sending error mail"
|
||||||
echo -e "An error occured during the execution of $SCRIPT ($ERR).\n\n$OUTPUT" | mailx -s "$(hostname) $SCRIPT failure" "$MAILTO"
|
echo -e "An error occured during the execution of $SCRIPT ($ERR).\n\n$OUTPUT" | $(dirname $0)/mail.sh "$(hostname) $SCRIPT failure"
|
||||||
echo "Sent"
|
echo "Sent"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -7,14 +7,11 @@ then
|
|||||||
UPDATES=$(echo -e "$UPDATES" | grep -v "testing repos\!")
|
UPDATES=$(echo -e "$UPDATES" | grep -v "testing repos\!")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "$UPDATES"
|
echo -en "$UPDATES"
|
||||||
|
|
||||||
if [ ! -z "$UPDATES" ]; then
|
if [ ! -z "$UPDATES" ]; then
|
||||||
HOST=$(hostname)
|
HOST=$(hostname)
|
||||||
FROM=$(cat ~/.host_mail)
|
echo -e "The following security updates are available for $HOST:\n\n$UPDATES\n\nIt is highly recommended that you perform these updates now" | $(dirname $0)/mail.sh "Security updates are available on $HOST"
|
||||||
DEST=$(cat ~/.admin_mail)
|
|
||||||
|
|
||||||
echo -e "The following security updates are available for $HOST:\n\n$UPDATES\n\nIt is highly recommended that you perform these updates now" | mailx -s "Security updates are available on $HOST" -r "$FROM" $DEST
|
|
||||||
echo "Mail sent"
|
echo "Mail sent"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user