LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-29-2005, 08:07 AM   #1
ZairSadiqov
LQ Newbie
 
Registered: Jan 2005
Location: Aze
Distribution: suse9.1
Posts: 7

Rep: Reputation: 0
Perl cgi Script can`t make file.Why?


I wrote a script. It works clear in console while i am in as root user.
browser:
http://localhost/cgi-bin/firstcgi.pl
can write to a file but can not creat.
is there administration problem?
is it possible to give extra grants to a script? or apache?
if you need i can write the script.
code here :
###########################start{}
#!/usr/bin/perl
$method=$ENV{'REQUEST_METHOD'};
if ($method eq "GET"){
$form_data=$ENV{'QUERY_STRING'};
}
else{
read(STDIN, $form_data, $ENV{'CONTENT_LENGTH'});
}
$form_data=~s/%(..)/pack("c", hex($1))/eg;
$form_data=~tr/+/ /;
@pairs=split("&", $form_data);
foreach $pair(@pairs){
($name, $value)=split(/=/, $pair);
$frm{$name}=$value;
}

&html_bashlat;
#open(FIN,">>makefilein.txt") or die "Fayl in acilmadi\n ";
open(FIL,"<makefilen.txt") or die "Fayl in acilmadi\n ";
#flock(FIN, 2) or die "Fayl ekskluziv olaraq baglanila bilinmedi\n ($!)";
#open(FIL,"+>makefilen.txt") or die "Fayl n acilmadi\n ";
#print FIN "salam ala nuppala \n";
$a=<FIL>+1;
close(FIL);
open(FIL,">makefilen.txt") or die "Fayl n acilmadi\n ";;
print FIL "$a";
close(FIL);
$F='eth'.$a;
open(NEWF, ">".$F);
print NEWF "$frm{'ip'}";
#print "$c $frm{'ip'}";
#print NEWF ($frm{'zirt'})."\n";
#print NEWF ($frm{'pirt'})."\n";
close(NEWF);
#$a=7;
#$a=$a+<FIL>;
#print "$a"."\n";
#print (<FIL>."\n");
#flock(FIN, 8) or die "Fayl ekskluzivlikden azad oluna bilinmedi\n ";
#close(FIN);
#print "$frm{'ip'}";
&html_kapat;
#system("chmod 0777 *");
exit;
sub baglanti_kurulamadi{
&html_bashlat;
print "<p><h2>";
print "$sunucu veri tabani sunucusuna baglanti kurulamadi!";
print "</h2>";
&html_kapat;
exit;
}
sub html_bashlat{
print "Content-type:text/html\n\n";
print "<html>\n";
#turkce karakterler sorunsuz gorunsun diye..
print "<meta http-equiv='Content-Type' ";
print " content='text/html; charset=iso-8859-9'>\n";
print "<meta http-equiv='Content-Type' ";
print " content='text/html; charset=windows-1254'>\n";
print "<body>\n";
}
sub html_kapat{
print "</body></html>\n";
}


#####################end;
thanks in advance.


Last edited by ZairSadiqov; 01-29-2005 at 08:42 AM.
 
Old 11-22-2006, 07:22 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
My guess is its a permissions problem. To be able to write to an existing file, you must have write permission on that file, but to be able to create a file, you must have write permission on the directory that will contain it, which would explain why it works if the file's already there.

This also explains why it works fine when run from the command line as root, because of course root almost certainly does have write permissions on the directory.
 
  


Reply



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
trying to add cgi-bin perl script. shizzle Linux - Networking 7 05-19-2005 01:24 AM
CGI/Perl script problems. Randvegeta Linux - Software 8 12-30-2004 12:24 AM
cgi-bin error regarding perl script hamish Linux - Software 11 12-09-2004 10:16 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
Need Help With My Perl/cgi Authentication Script dutch357 Programming 0 04-11-2003 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration