a cgi for view unix logs?

R

robertchen117

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) ==
 
O

Owen

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
 
T

tfe

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";'
 
J

Joe Smith

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
 
T

Tad McClellan

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 /;
 
C

Charlton Wilbur

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
 
A

Andrew DeFaria

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top