a cgi for view unix logs?

Discussion in 'Perl Misc' started by robertchen117@gmail.com, Feb 13, 2007.

  1. Guest

    I am trying to use this to output the last 100 lines to a cgi page,
    but because it do not print \n in HTML, so everything is mess up. I do
    not want to try to open a file, read the last 100 lines and close the
    file. Because I think it would be slow than Unix "tail".

    $done = system("tail -100 $filename")

    tail in cgi page, No return/new lines:
    DISSE0029I Current software package status is 'IC---'. DISSE0001I
    Operation successful. DISSE0609I The container 'NT' is skipped because
    the condition '$(os_name) == Windows_NT' is false. =================
    Software Package: "test_package^1.0" Operation: install Mode: not-
    transactional,not-undoable | force Time: 2007-02-13 00:24:35 Log File:
    ess.vip.dot.com:/tivoli/bin/swdis/work/test_package^1.0.log
    ================= squad.sjc.dot.com: DISSE0074I Operation successfully
    submitted. Distribution ID is 1278500431.238232. =================
    Software Package: "test_package^1.0" Operation: install Mode: not-
    transactional,not-undoable | force Time: 2007-02-13 00:24:46
    ================= sq.csco.dot.com: DISSE0155I Distribution ID:
    `1278500431.238232' DISSE0029I Current software package status is
    'IC---'. DISSE0001I Operation successful. DISSE0609I The container
    'NT' is skipped because the condition '$(os_name) ==
     
    , Feb 13, 2007
    #1
    1. Advertising

  2. Owen Guest

    On 12 Feb 2007 23:45:08 -0800
    "" <> wrote:

    > I am trying to use this to output the last 100 lines to a cgi page,
    > but because it do not print \n in HTML, so everything is mess up. I do
    > not want to try to open a file, read the last 100 lines and close the
    > file. Because I think it would be slow than Unix "tail".
    >
    > $done = system("tail -100 $filename")



    You might want to try using File::ReadBackwards

    Anyway, if you go the system call way, I think the simplest thing to do is write the output of the system call to a file, then read the file

    system("tail -100 $filename > 100lines.txt")

    Then open the file and print it.

    open my $LINES, "<", "100lines.txt" or die "Can't open 100lines.txt $!\n";
    while (<$LINES>) {
    print;
    print "<br>;
    }

    You don't give too many clues as to what you are doing, but you might get a clue from the above.


    Owen
     
    Owen, Feb 13, 2007
    #2
    1. Advertising

  3. tfe Guest

    An idea to read last 100 chars:
    my $nb=100;
    perl -e 'open(HANDLE,$file); seek(HANDLE,-$nb,SEEK_END); read(HANDLE,
    $contenu,$nb); print "Read: $contenu\n";'

    --
    tfe
    http://tfeserver.be


    On 13 fév, 09:12, Owen <> wrote:
    > On 12 Feb 2007 23:45:08 -0800
    >
    > "" <> wrote:
    > > I am trying to use this to output the last 100 lines to a cgi page,
    > > but because it do not print \n in HTML, so everything is mess up. I do
    > > not want to try to open a file, read the last 100 lines and close the
    > > file. Because I think it would be slow than Unix "tail".

    >
    > > $done = system("tail -100 $filename")

    >
    > You might want to try using File::ReadBackwards
    >
    > Anyway, if you go the system call way, I think the simplest thing to do is write the output of the system call to a file, then read the file
    >
    > system("tail -100 $filename > 100lines.txt")
    >
    > Then open the file and print it.
    >
    > open my $LINES, "<", "100lines.txt" or die "Can't open 100lines.txt $!\n";
    > while (<$LINES>) {
    > print;
    > print "<br>;
    > }
    >
    > You don't give too many clues as to what you are doing, but you might geta clue from the above.
    >
    > Owen
     
    tfe, Feb 13, 2007
    #3
  4. Joe Smith Guest

    wrote:
    > I am trying to use this to output the last 100 lines to a cgi page,
    > but because it do not print \n in HTML, so everything is mess up.


    Of course. For HTML, you have to explicitly provide a line break.

    print "<tt>$_</tt><br>" for (@lines);

    or

    print "<pre>",@lines,"</pre>";

    And if the text contains "<" or "&", you'll need to escape that.
    -Joe
     
    Joe Smith, Feb 13, 2007
    #4
  5. <> wrote:
    > I am trying to use this to output the last 100 lines to a cgi page,
    > but because it do not print \n in HTML, so everything is mess up. I do
    > not want to try to open a file, read the last 100 lines and close the
    > file. Because I think it would be slow than Unix "tail".
    >
    > $done = system("tail -100 $filename")



    print map "$_<br>", qx/ tail -100 $filename /;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 13, 2007
    #5
  6. >>>>> "rc" == robertchen117@gmail com <> writes:

    rc> I am trying to use this to output the last 100 lines to a cgi
    rc> page, but because it do not print \n in HTML, so everything is
    rc> mess up.

    In most cases, HTML treats white space as interchangeable, so there's
    no difference between a \n and a space. If you use your browser's
    "View Source" function, you'll be able to see that the newlines are
    actually present.

    The solution is to bring the way you send the output and the way you
    expect the output to appear into agreement. If you want the newlines
    in your output to be meaningful, send a Content-Type of text/plain.
    If you want to send HTML, alter the output you produce so that it
    produces the appearance you want. Neither of these is a Perl-specific
    problem.

    Charlton



    --
    Charlton Wilbur
     
    Charlton Wilbur, Feb 13, 2007
    #6
  7. wrote:
    > I am trying to use this to output the last 100 lines to a cgi page,
    > but because it do not print \n in HTML, so everything is mess up. I do
    > not want to try to open a file, read the last 100 lines and close the
    > file. Because I think it would be slow than Unix "tail".
    >
    > $done = system("tail -100 $filename")
    >
    > tail in cgi page, No return/new lines:
    > DISSE0029I Current software package status is 'IC---'. DISSE0001I
    > Operation successful. DISSE0609I The container 'NT' is skipped because
    > the condition '$(os_name) == Windows_NT' is false. =================
    > Software Package: "test_package^1.0" Operation: install Mode: not-
    > transactional,not-undoable | force Time: 2007-02-13 00:24:35 Log File:
    > ess.vip.dot.com:/tivoli/bin/swdis/work/test_package^1.0.log
    > ================= squad.sjc.dot.com: DISSE0074I Operation successfully
    > submitted. Distribution ID is 1278500431.238232. =================
    > Software Package: "test_package^1.0" Operation: install Mode: not-
    > transactional,not-undoable | force Time: 2007-02-13 00:24:46
    > ================= sq.csco.dot.com: DISSE0155I Distribution ID:
    > `1278500431.238232' DISSE0029I Current software package status is
    > 'IC---'. DISSE0001I Operation successful. DISSE0609I The container
    > 'NT' is skipped because the condition '$(os_name) ==
    >

    Use the <pre> tag. That's what it's for!

    --
    Andrew DeFaria <http://defaria.com>
    Imagination is more important than knowledge. - Albert Einstein
     
    Andrew DeFaria, Feb 13, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    1,702
    Dave Thompson
    Jan 10, 2005
  2. Replies:
    18
    Views:
    659
    Dave Thompson
    Jan 10, 2005
  3. Parthiv Joshi
    Replies:
    1
    Views:
    820
    Samuel L Matzen
    Jul 6, 2004
  4. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    316
    Michele Dondi
    Jan 22, 2004
  5. sunckell

    Sorting non-compresses Unix logs

    sunckell, Jan 3, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    110
    Gunnar Hjalmarsson
    Jan 3, 2006
Loading...

Share This Page