Updated mailfrom address to get hostname and domain from server

This commit is contained in:
Matthew McKinnon 2016-03-26 21:59:06 +10:00
parent bd2c1211e0
commit 6cb8fcdd8c
3 changed files with 9 additions and 7 deletions

View File

@ -3,7 +3,7 @@
MAILTO="support@comprofix.com"
SMTP=mail.comprofix.com
THISSERVER=`hostname --fqdn`
MAILFROM="support@comprofix.com"
MAILFROM="$(hostname)@$(dnsdomainname)"
#Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
@ -12,7 +12,7 @@ test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
#/usr/sbin/logwatch --output mail
/usr/sbin/logwatch
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILTO>" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q
#Note: It's possible to force the recipient in above command
#Just pass --mailto address@a.com instead of --output mail

View File

@ -16,10 +16,12 @@
MAILTO="support@comprofix.com"
SMTP=mail.comprofix.com
AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log"
THISSERVER=`hostname --fqdn`
MAILFROM="support@comprofix.com"
MAILFROM="$(hostname)@$(dnsdomainname)"
#
# End of user configuration section
@ -60,7 +62,7 @@ check_return() {
}
send_error_email() {
sendemail -f "$THISSERVER <$MAILTO>" -t $MAILTO -u "[$THISSERVER] There was an error whilst running $0" -s $SMTP
sendemail -f "$THISSERVER <$MAILFROM>" -t $MAILTO -u "[$THISSERVER] There was an error whilst running $0" -s $SMTP
"Hello,
@ -140,7 +142,7 @@ See the logfile for more info: vim $LOGFILE
Regards. " >/tmp/servermail.msg
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILTO>" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)"
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)"
echo "`date` [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
fi

View File

@ -3,7 +3,7 @@ MAILTO="support@comprofix.com"
SMTP=mail.comprofix.com
LOGFILE="/var/log/diskalert.log"
THISSERVER=`hostname --fqdn`
MAILFROM="support@comprofix.com"
MAILFROM="$(hostname)@$(dnsdomainname)"
startlogging() {
echo $DASHES2 >> $LOGFILE
@ -53,7 +53,7 @@ See the logfile for more info: vim $LOGFILE
Regards, " >/tmp/diskalertmail.msg
cat /tmp/diskalertmail.msg | sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILTO>" -u "[$THISSERVER] is running out of disk space"
cat /tmp/diskalertmail.msg | sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space"
echo "`date` [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
fi