T
Tristan Knowles
Hi,
After reading up on Ruby I thought it sounded good and
decided to learn it so I can manipulate my files on my
linux server such as log, csv, conf etc. Anyway, i'm
a beginner when it comes to programming, so bear with
me.
I use the Asterisk PBX and came across this script
here which reads a csv file and puts each record into
an html table:
http://rubyforge.org/snippet/detail.php?type=3Dsnippet&id=3D76
Anyway, I thought I would then apply this basic
concept to a log file, but I cannot get it to display
through a web browser. Here is my script:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#!/usr/bin/ruby
My_Title =3D "Testing Log Read"
Log_File =3D "/var/log/apache2/error.log"
require 'cgi'
cgi =3D CGI.new
printf cgi.header("Content-type" =3D> "text/html\n\n")
printf "<html>\n<head>\n"
printf "<title>#{My_Title}</title>\n"
printf "</head>\n<body bgcolor=3D\"#efefef\">\n"
printf "<table width=3D\"80%\">\n<tr><td>Call
records</td></tr>\n"
if File.exists? Log_File
lines =3D File.open(Log_File).readlines
lines.each_with_index do |line, index|
printf " <tr%s>\n <td>%d</td>",
index % 2 =3D=3D 0 ? ' bgcolor=3D"#dddddd"' : '
bgcolor=3D"#cccccc"', index + 1=20
entries =3D line.chop.split(/\n/)
entries.each_with_index do |field, index|
printf "<td>%s</td>", entries
end
printf "\n</tr>\n"
end
else
printf "No File Found\n"
end
printf "</body>\n</html>"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
If I comment out all the printf commands related to
web and cgi, and run it through the shell, it seems to
be taking each line and putting it into <tr><td>
brackets, but I can't get it to display through a
browser, it stops at the third printf command.
I have tried heaps of different things, but feel like
i'm running around in circles now.
Any advise with this one?
Cheers.
Tristan
=09
=09
=09
___________________________________________________________=20
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voic=
email http://uk.messenger.yahoo.com
After reading up on Ruby I thought it sounded good and
decided to learn it so I can manipulate my files on my
linux server such as log, csv, conf etc. Anyway, i'm
a beginner when it comes to programming, so bear with
me.
I use the Asterisk PBX and came across this script
here which reads a csv file and puts each record into
an html table:
http://rubyforge.org/snippet/detail.php?type=3Dsnippet&id=3D76
Anyway, I thought I would then apply this basic
concept to a log file, but I cannot get it to display
through a web browser. Here is my script:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#!/usr/bin/ruby
My_Title =3D "Testing Log Read"
Log_File =3D "/var/log/apache2/error.log"
require 'cgi'
cgi =3D CGI.new
printf cgi.header("Content-type" =3D> "text/html\n\n")
printf "<html>\n<head>\n"
printf "<title>#{My_Title}</title>\n"
printf "</head>\n<body bgcolor=3D\"#efefef\">\n"
printf "<table width=3D\"80%\">\n<tr><td>Call
records</td></tr>\n"
if File.exists? Log_File
lines =3D File.open(Log_File).readlines
lines.each_with_index do |line, index|
printf " <tr%s>\n <td>%d</td>",
index % 2 =3D=3D 0 ? ' bgcolor=3D"#dddddd"' : '
bgcolor=3D"#cccccc"', index + 1=20
entries =3D line.chop.split(/\n/)
entries.each_with_index do |field, index|
printf "<td>%s</td>", entries
end
printf "\n</tr>\n"
end
else
printf "No File Found\n"
end
printf "</body>\n</html>"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
If I comment out all the printf commands related to
web and cgi, and run it through the shell, it seems to
be taking each line and putting it into <tr><td>
brackets, but I can't get it to display through a
browser, it stops at the third printf command.
I have tried heaps of different things, but feel like
i'm running around in circles now.
Any advise with this one?
Cheers.
Tristan
=09
=09
=09
___________________________________________________________=20
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voic=
email http://uk.messenger.yahoo.com