On 2019-07-27 Christian Garbs <mi...@cgarbs.de> wrote:
> Package: exim4-base
> Version: 4.92-8+deb10u1
> Severity: normal
> Tags: ipv6

> After the update from Stretch to Buster, on one of my systems
> /etc/cron.daily/exim4-base failed on every run with just

> hostname: Name or service not known

> as an error message.

> I could trace this to the usage of "hostname --fqdn" in the script.
> On this (and so far only on this) system this call simply fails:

> $ hostname --fqdn
> hostname: Name or service not known
[...]
> I don't yet know why, but I indeed have two hostnames:

> $ hostname --all-fqdns
> het.cgarbs.de het.cgarbs.de 

> I guess one is for the IPv4 connection and the other for IPv6.
[...]

Hello Christian,

on this system, hostname --fqdn succeeds but hostname --all-fqdns fails:
--
ametzler@argenau:~$ hostname --fqdn ; echo FQDN $? ; hostname --all-fqdns ; 
echo fqdnS $?
argenau.bebt.de
FQDN 0

fqdnS 0
--

In /etc/hosts I have got 127.0.0.1 as localhost and 127.0.1.1 as my
normal FQDN, which I think is not totally broken.

> Is there another way to get a proper hostname, perhaps from Exim
> or the Exim configuration, that can be used in /etc/cron.daily/exim4-base
> instead of calling "hostname --fqdn"?

There is
/usr/sbin/exim4 -bP primary_hostname
or
/usr/sbin/exim4 -be '${primary_hostname}'

How about the attached patch?

cu Andreas
-- 
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'
--- debian/exim4-base.cron.daily	2019-07-27 17:38:42.325457369 +0200
+++ /tmp/cron.daily	2019-07-28 14:06:59.414272250 +0200
@@ -25,6 +25,13 @@ fi
 [ -f /etc/default/exim4 ] && . /etc/default/exim4
 
 SPOOLDIR="$(exim4 -bP spool_directory | sed 's/.*=[[:space:]]\(.*\)/\1/')"
+if [ -n "$E4BCD_DAILY_REPORT_TO" ] || [ "$E4BCD_WATCH_PANICLOG" != "no" ] ; then
+	# Only needed for mail subject.
+	if ! HOSTNAME=$(/usr/sbin/exim4 -be '${primary_hostname}'); then
+		HOSTNAME="$(hostname)"
+	fi
+fi
+
 
 # The log processing code used in this cron script is not very
 # sophisticated. It relies on this cron job being executed earlier than
@@ -43,11 +50,11 @@ if [ -n "$E4BCD_DAILY_REPORT_TO" ]; then
     if [ "$(< /var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" | wc -l)" -gt "0" ]; then
       < /var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" \
                 | eximstats $E4BCD_DAILY_REPORT_OPTIONS \
-                | mail -s"$(hostname --fqdn) Daily e-mail activity report" \
+                | mail -s"${HOSTNAME} Daily e-mail activity report" \
 		    $E4BCD_DAILY_REPORT_TO
     else
       echo "no mail activity in this interval" \
-                | mail -s"$(hostname --fqdn) Daily e-mail activity report" \
+                | mail -s"${HOSTNAME} Daily e-mail activity report" \
 		    $E4BCD_DAILY_REPORT_TO
     fi
   else
@@ -73,7 +80,7 @@ if [ "$E4BCD_WATCH_PANICLOG" != "no" ];
     if [ -z "$E4BCD_PANICLOG_NOISE" ] || grep -vq "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog; then
       log_this "ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken"
       if ! printf "Subject: exim paniclog on %s has non-zero size\nTo: root\n\nexim paniclog /var/log/exim4/paniclog on %s has non-zero size, mail system might be broken. Up to ${E4BCD_PANICLOG_LINES} lines are quoted below.\n\n%s\n" \
-      "$(hostname --fqdn)" "$(hostname --fqdn)" \
+      "${HOSTNAME}" "${HOSTNAME}" \
       "$(if [ -z "$E4BCD_PANICLOG_NOISE" ] ; then tail -n "${E4BCD_PANICLOG_LINES}" /var/log/exim4/paniclog ; else grep -v "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog | tail -n "${E4BCD_PANICLOG_LINES}" ; fi)" \
       | exim4 root; then
         log_this "PANIC: sending out e-mail warning has failed, exim has non-zero return code"

Reply via email to