Solved

IIS4 and perlscripts that write to a file

Posted on 1998-07-22
5
238 Views
Last Modified: 2010-03-05
I got my perlscripts running on IIS4, they respond ok to the browser.
But the scripts that are supposed to write to a file with this code:

open(OUTFILE, ">bla.txt");
print (OUTFILE "test\n");
close(OUTFILE);

Just don't write to the file. There is no error message.

print "Content-type: text/html\n\n";
print "here we are";

After the writing statement gives the right output to the browser.

Also when the script is run from the command prompt it works ok.

I checked security, and I don't think there is a problem there.
0
Comment
Question by:sybe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1208594
Does the file exist? Does the file exist in the directory you think it should exist in?
Try doing:

open(OUTFILE, ">bla.txt") || die "Content-type: text/html\n\n$!\n\n";

If that doesn't tell you anything good (like why the open failed), and you're sure of the directory that the file is being put in, and you're on a UNIX server, then perhaps something is odd with your umask, but cross that bridge when  you fall off it.
0
 
LVL 28

Author Comment

by:sybe
ID: 1208595
Now this is an interesting suggestion, When I do as you say, the code is as follows:
=======================
#!usr/local/bin/perl

open(OUTFILE, ">>/Inetpub/scripts/perl/test2/bla.txt") || die "Content-type: text/html\n\n$!\n\n";
print (OUTFILE "test\n");
close(OUTFILE);

open(READFILE, "/Inetpub/scripts/perl/test2/bla.txt");
$line = <READFILE>;
close(READFILE);

print "Content-type: text/html\n\n";
print "$line<BR>\n";
print "here we are";
============================

and the response in the browser is:

"Permission denied "


Using the code that I had before:
========================
#!usr/local/bin/perl

open(OUTFILE, ">>/Inetpub/scripts/perl/test2/bla.txt");
print (OUTFILE "test\n");
close(OUTFILE);

open(READFILE, "/Inetpub/scripts/perl/test2/bla.txt");
$line = <READFILE>;
close(READFILE);

print "Content-type: text/html\n\n";
print "$line<BR>\n";
print "here we are";
============================

The response in the browser is:

phrase from bla.txt
here we are

==========================

So it might after all be a permission thing.

What permissions are needed on NT ??

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208596
Clearly, you don't have write permissions.  Let me guess... the script works if you run it from the command line, but not if you run it from the server, right?  So the question is, what is the current directory when you're running from the server, and who cares, as you don't have write permissions there.  Thus, open the file in a directroy where you have write permissions.... (Ummm, for instance, the one you're in when you're running the script manually from the command line..., or /tmp, or the value of $ENV{tmp} or the value of $ENV{temp} or ....


0
 
LVL 28

Author Comment

by:sybe
ID: 1208597
When I give everyone -> full control, it works, now it's only a matter of denying what rights are not needed.

Thanks, it helped me a lot.

What does

|| die "Content-type: text/html\n\n$!\n\n

exactly do ? display the error message ?
so $! is the error message
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208598
$! is indeed the error message.

But!!!! STOP!!!!!!!!!!!!!!!!!!!! STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!STOP!!!!!!!!!!!!!!!!!!!!
DO NOT GIVE EVERYONE FULL CONTROL!!! If you do, some nice person from the outside world could easily come in and take you down.  Hard!!!!  Instead, give everyone
full control to, say, C:\temp, and open the files there...

open (OUTFILE, ">>/temp/bla.txt") || die ....

You never want anyone writing to that scripts directory.  A better solution is to find out who the user is when executing cgi scripts (I can't remember for IIS, but it may well be "NOBODY") and give that user write rights to a data directory, which no-one else has write-rights to.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question