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
|
||||
|
||||
SCRIPT=$1
|
||||
|
||||
shift
|
||||
|
||||
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=${PIPESTATUS[0]}
|
||||
|
||||
OUTPUT=$(cat /tmp/$FILE_ID.log)
|
||||
rm /tmp/$FILE_ID.log
|
||||
|
||||
if [ $ERR -ne 0 ]; then
|
||||
MAILTO=$(cat "$HOME/.admin_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"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -7,14 +7,11 @@ then
|
||||
UPDATES=$(echo -e "$UPDATES" | grep -v "testing repos\!")
|
||||
fi
|
||||
|
||||
echo -e "$UPDATES"
|
||||
echo -en "$UPDATES"
|
||||
|
||||
if [ ! -z "$UPDATES" ]; then
|
||||
HOST=$(hostname)
|
||||
FROM=$(cat ~/.host_mail)
|
||||
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 -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"
|
||||
echo "Mail sent"
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user