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

Dear all, I have sendmail box here and whenever I updated the /etc/aliases I have to send a broadcast with to all user here about the changes. I just wonder if there is any handly Perl script to convert the /etc/aliases file to HTML file so that I can publish this on the internal web server. Thank you, Perly

Replies are listed 'Best First'.
RE: Sendmail Aliases to HTML?
by t0mas (Priest) on Aug 23, 2000 at 16:43 UTC
    open(HF,">aliases.html") or die "$!"; open(AF,"</etc/aliases") or die "$!"; print HF "<HTML><HEAD><TITLE>Our new alaises</TITLE></HEAD><BODY><PRE> +"; while (<AF>) {print HF;} print HF "</PRE></BODY></HTML>"; close(HF) or die "$!"; close(AF) or die "$!";
    Update:merlyn is right as usual. I don't put <,> or & in my /etc/aliases, just plain Postmaster: root stuff... Sorry.

    Change the while (<AF>) {print HF;} to
    while (<AF>) { s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; print HF;}
    That will make it "semi-encoded" and not break on >,< or &.

    merlyns solution with LWP is a better one of cause, but the above might be good enough if you don't have and don't want to install LWP.

    /brother t0mas
      That fails if there are any less-thans, greater-thans, or ampersands in the text. And HTML has no equivalent to our <code> tags. {grin} So, you need to entitize the file. If you've got LWP installed, that's trivial. See the snippet I just added: Convert text file to HTML.

      -- Randal L. Schwartz, Perl hacker

Re: Sendmail Aliases to HTML?
by le (Friar) on Aug 23, 2000 at 16:03 UTC
    Your question is not quite clear to me, and I guess to many others, too.

    1. What do you mean with broadcast?
    2. Why would you want to publish the aliases file via Web?