diff --git a/mail.sh b/mail.sh new file mode 100755 index 0000000..8973343 --- /dev/null +++ b/mail.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +MAILFROM=$(cat ~/.host_mail) +MAILTO=$(cat "$HOME/.admin_mail") + +SUBJECT=$1 + +cat | mailx -s "$SUBJECT" -r "$MAILFROM" "$MAILTO" \ No newline at end of file diff --git a/mail_wrap_script.sh b/mail_wrap_script.sh index 2452287..276115c 100755 --- a/mail_wrap_script.sh +++ b/mail_wrap_script.sh @@ -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 diff --git a/security-updates-check.sh b/security-updates-check.sh index 0106ff9..4f396e8 100755 --- a/security-updates-check.sh +++ b/security-updates-check.sh @@ -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