Bob Proulx
2010-Mar-21 18:27 UTC
[Logcheck-devel] Bug#574858: logcheck: Does not ignore unresolvable hostname
Package: logcheck Version: 1.3.7 Severity: normal After installing logcheck on a system it posted an error to the cron mail address hourly. An untrapped script error was posting stderr output to cron. It originated here: # Hostname either fully qualified or not. if [ $FQDN -eq 1 ]; then HOSTNAME="$(hostname --fqdn)" > /dev/null 2>&1 else HOSTNAME="$(hostname --short)" > /dev/null 2>&1 fi There has obviously been an attempt to silence errors in this area. Unfortunately that isn't the correct shell syntax to do this. That is silencing the output of the assignment and not of the hostname command itself. Therefore if the hostname isn't registered in DNS the error message is still emitted to stderr. $ hostname --short hostname: Unknown host $ hostname --long hostname: Unknown host I believe what was intended was the following: # Hostname either fully qualified or not. if [ $FQDN -eq 1 ]; then HOSTNAME="$(hostname --fqdn 2>/dev/null)" else HOSTNAME="$(hostname --short 2>/dev/null)" fi However this will still fail to produce a correct hostnames in the face of an unresolvable hostname in DNS. And I will guess that the short hostname is the more typical case these days since it is the default in Debian. Therefore it would be better if for the short case the hostname is received and then truncated at the first dot if one exists. This will avoid this error for the short case entirely. Because the script is already a #!/bin/bash script it is safe to use a POSIX shell parameter expansion construct. Here is an improvement. # Hostname either fully qualified or not. if [ $FQDN -eq 1 ]; then HOSTNAME=$(hostname --fqdn 2>/dev/null) test -z "$HOSTNAME" && HOSTNAME=$(hostname) else HOSTNAME=$(hostname) HOSTNAME=${HOSTNAME%%.*} fi I have tested this on my system and it produced the desired result. The process of determining the FQDN using 'hostname --fqdn' is still problematic since the hostname command doesn't do the Right Thing there but that is a different topic. Determining the one single domain name of a host is fraught with subtle issues. Note: Since shell word splitting isn't done on variable assignment the extra quotes are not needed there to protect the right hand side value from word splitting. For example: $ foo=$(echo "one two three") $ echo "$foo" one two three Thanks, Bob
Hannes von Haugwitz
2010-Apr-16 09:45 UTC
[Logcheck-devel] Bug#574858: Bug#574858: logcheck: Does not ignore unresolvable hostname
tags 574858 +moreinfo thanks Bob Proulx wrote: > I believe what was intended was the following:> > # Hostname either fully qualified or not. > if [ $FQDN -eq 1 ]; then > HOSTNAME="$(hostname --fqdn 2>/dev/null)" > else > HOSTNAME="$(hostname --short 2>/dev/null)" > fi >Fixed in 1.3.8.> However this will still fail to produce a correct hostnames in the > face of an unresolvable hostname in DNS. And I will guess that the > short hostname is the more typical case these days since it is the > default in Debian. Therefore it would be better if for the short case > the hostname is received and then truncated at the first dot if one > exists. This will avoid this error for the short case entirely. > Because the script is already a #!/bin/bash script it is safe to use a > POSIX shell parameter expansion construct. Here is an improvement. > > # Hostname either fully qualified or not. > if [ $FQDN -eq 1 ]; then > HOSTNAME=$(hostname --fqdn 2>/dev/null) > test -z "$HOSTNAME" && HOSTNAME=$(hostname) > else > HOSTNAME=$(hostname) > HOSTNAME=${HOSTNAME%%.*} > fi >With the above fix the error message shouldn't occur any longer. Why should logcheck bypass an unresolvable hostname? Wouldn't it be better if the administrator fixed the hostname issue instead? Greetings Hannes
Debian Bug Tracking System
2010-Apr-16 09:48 UTC
[Logcheck-devel] Processed: Re: Bug#574858: logcheck: Does not ignore unresolvable hostname
Processing commands for control at bugs.debian.org:> tags 574858 +moreinfoBug #574858 [logcheck] logcheck: Does not ignore unresolvable hostname Added tag(s) moreinfo.> thanksStopping processing here. Please contact me if you need assistance. Debian bug tracking system administrator (administrator, Debian Bugs database)
Possibly Parallel Threads
- Bug#582060: logcheck-database: bind network unreachable errors
- Bug#568815: Redundant messages from dhcpd in logcheck output in "server" mode.
- Bug#569843: logcheck-database: acpid filter misses trailing white space
- Bug#317741: logcheck-database: fails to ignore properly some lines from 'rbldnsd'
- Bug#306388: add ignore line for udhcpd