Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > a cgi for view unix logs?

Reply
Thread Tools

a cgi for view unix logs?

 
 
robertchen117@gmail.com
Guest
Posts: n/a
 
      02-13-2007
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) ==

 
Reply With Quote
 
 
 
 
Owen
Guest
Posts: n/a
 
      02-13-2007
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
 
Reply With Quote
 
 
 
 
tfe
Guest
Posts: n/a
 
      02-13-2007
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 <dont_reply_to...@pcug.org.au> wrote:
> On 12 Feb 2007 23:45:08 -0800
>
> "robertchen...@gmail.com" <robertchen...@gmail.com> 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



 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      02-13-2007
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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-13-2007
<> 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
 
Reply With Quote
 
Charlton Wilbur
Guest
Posts: n/a
 
      02-13-2007
>>>>> "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

 
Reply With Quote
 
Andrew DeFaria
Guest
Posts: n/a
 
      02-13-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
How to make a week view and day view calendar just like month view calendar in .NET ? Parthiv Joshi ASP .Net Web Controls 1 07-06-2004 03:15 PM
Windows/UNIX compatibility problem with C++ via CGI Der Andere C++ 2 06-04-2004 10:00 PM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-21-2004 11:28 PM



Advertisments