Getting hostname using ssh

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.

why would it...if when I run it manually it works out great!!

Why would what?

What are you running manually?

Do you have the output from hexdump -C that I asked for?

I ran the script with little modifications and it is working fin now...

thanks for all your help:) Corona688

What is the difference from this line

ssh $host exec /bin/sh -s $HOSTNAME 2>&1

to this line?

ssh $host exec /bin/sh -s $HOSTNAME 2>/dev/null

One of them sends standard error into /dev/null, which basically gets rid of them. I'd been trying to keep those lines -- the "echo stuff >&2" in the <<EOF block -- and send them into your logfile, but if that was the line that fixed it, they must have been ending up in the gzip instead. Sigh. :confused:

How can I send the input of the remote server into my logfile. No output was sent to the gzip files, since the html files look ok.

The way it was originally? ssh $host exec /bin/sh -s $HOSTNAME 2>&1 ?