LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-06-2010, 05:48 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Unable to append to a file through perl/CGI


Hi folks,
Please look at the following code, where I'm trying to demonstrate the file locking concept through Perl/CGI.
Here is the script which I tried.
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
print "Content-type: text/html\n\n";
print <<EOF;
<html>
<head>
<title>File Locking</title>
</head>
<body bgcolor = "#556677"></body>
<br><br>
<center><h1>Demonstrating File locking concept</h1></center>
EOF
my $myfile = "Employee.txt";
my $employee = "Manoj";
open(MYFILE, "$myfile");
flock(MYFILE, 1);
while(defined($a=<MYFILE>)) {
  if ($a=~m/^$employee$/) {
  print "<center>You are already in the list!\n</center>";
  exit;
  }
}
flock(MYFILE,8);
close(MYFILE);
open(ASH, ">> $myfile");
flock(ASH, 2);
print ASH $employee;
print "<center>You are now in the list!\n</center>";
flock(ASH,8);
close(ASH);
print "<body><html>";
Here, I'm not able to append the text and also unable to lock(shared lock) the file.
For your information, this is executing fine when I run the same as as
Code:
perl filelock.cgi
But when I run the same script in a browser, I'm not getting it fine.
Please assist me.
 
Old 04-06-2010, 12:48 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
Check your error logs. You don't need use warnings, you have -w
And use is not for warnings anyway.
 
Old 04-06-2010, 07:44 PM   #3
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
The script has a whole world of different capabilities when run as a logged-in user compared to running as a CGI under a HTTP server userID. One principle of security is to disallow writes in the document root, server root, and cgi-bin directory.
How do you run a script in a browser?

--- rod.
 
  


Reply

Tags
cgi, file


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
while loop creates a problem for a file opened in append mode for writing in PERL gaynut Programming 2 07-28-2008 07:26 PM
[Perl] append to new file noir911 Programming 5 02-08-2007 06:38 AM
[Perl] append columns to file noir911 Programming 3 02-08-2007 05:29 AM
Perl cgi Script can`t make file.Why? ZairSadiqov Linux - Software 1 11-22-2006 07:22 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM


All times are GMT -5. The time now is 02:28 PM.

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