unixdisk has asked for the wisdom of the Perl Monks concerning the following question:

I collect data from 'n' servers and redirect the output to TXT file & email my Manager however now requriment is to attach the output in HTML as it's easy to read rather than TXT file.

Please let me know how to store the data in html & send it via email. Thanks.

Replies are listed 'Best First'.
Re: HTML static output
by Anonymous Monk on Apr 16, 2014 at 06:56 UTC

    Please let me know how to store the data in html & send it via email. Thanks.

    I have some ideas, like save the html and not the text

    Use the Perl documentation and CPAN and MetaCPAN search engine to find modules for "format html" and "safe html" and "send mail" and "email attach html"

    Then look and pick one thing which has good reviews good comments and lots of tests and lots of pass tester reports and

    And pick one and give it a try to see if it works for you :)

      I'll repharse my question:Collect system information from unix server like df, ntpq, etc this output is like txt output instead of that need in html output, how to do it?

        The really easy way is to output the text in HTML like the following:

        use HTML::Escape 'escape_html'; my $text= collect_output_as_txt( @servers ); my $title= "Report for servers " . join ",", @servers; $text= escape_html( $text ); print <<HTML; <html> <head><title> $title </title></head> <body> <pre> $text </pre> </body> </html> HTML

        If you want more fancy formatting, you will need to parse the output of each command and then fill the HTML appropriately.

        I'll repharse my question:Collect system information from unix server like df, ntpq, etc this output is like txt output instead of that need in html output, how to do it?

        Well ok, that takes care of "save the html" portion, for the rest, my idea, I'd solve the problem the exact same way

        I'd probably use what Corion said in addition to
        HTML::FromText - converts plain text to HTML
        Text::Autoformat - Automatic text wrapping and reformatting

Re: HTML static output
by ww (Archbishop) on Apr 16, 2014 at 10:44 UTC

    Please ask your manager to authorize and send USD1200 + 47.99 shipping and handling to ww, 123 Main, Foobar, BL 2Y174-LL3 in payment for this work you're trying to outsource.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.

    check Ln42!

Re: HTML static output
by Yaerox (Scribe) on Apr 16, 2014 at 10:18 UTC

    Did I got it? You don't want to attach anymore, now you want to post the content of the file as Mail-Body in HTML format?

    Build a Script which formats your content of output.txt, use Net::SMTP Module to send mails. Append your already formatted html body to your mail using the usual data function of the module.

    I hope I could help.

    Best regards

Re: HTML static output
by stonecolddevin (Parson) on Apr 16, 2014 at 17:44 UTC

    Use munin.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past