Hmm. Maybe your cfg2html command is printing useless chatter that ends up in the gz file? Try hexdump -C corrupted.gz | less
to see if there's readable text on the top of it.
If there is, here's how you fix it.
while read host
do
# Here-document is an alternative to feeding it a script file
# Everything between <<"EOF" and EOF gets fed into the remote host's shell.
#
# the script creates the html, and compresses it to stdout.
# we take stdout and put it into ${host}-config.gz
# we ignore stderr.
ssh $host exec /bin/sh -s $HOSTNAME 2>/dev/null > ${host}-config.html.gz <<"EOF"
# If you echo anything here, send it into >&2, i.e. stderr
echo "---------------- RUNNING HEALTH CHECK FOR $HOSTNAME ----------------" >&2
echo "---------------- (Remote host is $1) ----------------" >&2
# Everything in this block gets sent literally. $(hostname) is remote.
# redirecting everything in case cfg2html is chattering
cfg2html-linux -xApo /tmp/ >/dev/null 2>/dev/null
# gzip to standard output, instead of resaving to file.gz
# standard output goes across the ssh connection and is saved into ${host}-config.html.gz
/bin/gzip - < /tmp/"$(hostname)".html
rm -f /tmp/$(hostname).html
# MUST be at the beginning of the line. Do not indent!
EOF
done < $PATH_TMP/servers/host_linux2_test >> $PATH_TMP/Linux_cfg2html.log
Ignoring stderr up top there may not be necessary but this should cover all the bases. Put it back to 2>&1 once it works so you can get log messages out too.