LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-01-2007, 05:03 PM   #1
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
CGI script to view log files


I'm trying to get a basic perl script to view some log files over the web for some users. For starters, I have this:

Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<html><title>Log File Viewer</title><body>";
print "<h1><center><font color=white>Log File Viewer</h1></center></font>";
print "<body bgcolor=black>";
print "<TABLE border=1><td>";
#my $tail=`tail -100 /var/log/twantrd.messages`;
open(LOG, "/var/log/twantrd.messages") or die "Can't open file $!";
print <LOG>;
close(LOG);
#print "<font color=red>$tail</font>";
print "</td></TABLE>";
print "</body></html>";
The contents of the log does display however all the lines wrap around making it unreadable. Is there a way to display all the carriage returns of the log file via html? Thanks.

-twantrd
 
Old 03-01-2007, 07:08 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Print <PRE> tags around your log file:

Code:
print "<PRE>\n";
print <LOG>;
print "</PRE>\n";
--- rod
 
Old 03-02-2007, 02:59 AM   #3
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Original Poster
Rep: Reputation: 52
Ahhh, thanks!

I have one more question. I'm trying to setup a simple cgi script in perl that will scp some files when it's being called on via the web. For example, http://serverA/cgi-bin/scp.pl, will then run my perl script. The code is simple:

Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";
system("/usr/bin/scp user@host:/data/log.file /tmp/log.file");
However, nothing prints on screen and my file never gets scp'd over. BUT, if I wrote this in a bash script, it works just fine. What's wrong with my perl syntax?

-twantrd
 
Old 03-02-2007, 10:11 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
I'm a bit confused about that last post. The link that you posted seems to point to a holding URL that is for sale. That aside, are you saying that you have one script calling another script? Also, I'm confused about your reference to running a bash script and seeing output on your console. If you run a script that writes to standard output as a CGI, the standard output goes to the HTTP socket that is opened by the HTTP server. That's the whole essence of how CGI works. There are some differences between the contexts of running any script, bash, perl, whatever, as an ordinary user from the commandline, and as the user that the web server runs as in the CGI context. One difference is the permissions normally assigned to the cgi-bin directory. As a CGI, your script is trying to write to the cgi-bin directory, which the web server should not have write access to (a fundamental security issue).
Please clarify what you are seeing (or not seeing), in both the test and production situations.

--- rod.
 
Old 03-02-2007, 10:19 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Okay, re-examining your question, I think I see what you may be questioning. You are printing the first line of the HTTP header, but the rest of the HTML is missing. You should probably create a proper HTML page with the <html> <head></head> <body> </body> </html> components. Some confirmation message in the body would be good, too.
I assume you have arranged ssh keys to permit paswordless secure copies.
--- rod.

Last edited by theNbomr; 03-02-2007 at 10:20 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a script to change web log files? tomwgf Linux - Desktop 6 02-07-2007 09:38 AM
How to parse log files into text view using GLADE shandy^^^ Programming 8 02-07-2006 08:13 PM
script to clear log files kushalkoolwal Programming 8 01-24-2006 07:11 PM
Python CGI script can't write files, permission denied The_Nerd Programming 4 03-17-2005 12:19 PM
Can log files be time stamped? (such as FTP login and transfer log files) bripage Linux - Networking 6 08-08-2002 10:55 PM


All times are GMT -5. The time now is 11:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration