[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Writing to a file problems..

OK, I wrote this program which needs to write out to a file, and it worked initially.  But for some reason, it won't
work now.  I didn't change the file at all, and it just stopped writing to the file.  It was still running and doing everything correctly, except opening a file for writing.

I've tried several things, and wrote a simplified version for easier testing, and found that my server wasn't allowing the script to open a file for writing when called from a web page (a form submission), but it worked fine when
I ran it from the command line.

The files have 775 permissions.  Any ideas?  Here's the test script I wrote:

#!/usr/bin/perl
# print the header to start the output page
print "Content-type: text/html\n\n";
print "<HTML><BODY>\n";

open(IN, "week-3-7--3-13.txt");             # Open the file
@lines = <IN>;               # Read it into an array
close(IN);                   # Close the file

open(OUT, ">newfile.txt");          # Open the file
print OUT "@lines";             # Write updated scores to the file
close(OUT);                   # Close the file

print "@lines";
print "</BODY></HTML>";
0
jbirk
Asked:
jbirk
1 Solution
 
b2piCommented:
Most likely, your server is running the script as a user other than you (like nobody).  Try setting default permissions to 777.
0
 
b2piCommented:
Oops, too quick on the trigger.... That should be 666 for your data files.



By the way, you can save yourself the points by checking out http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html


0
 
ozoCommented:
open(OUT, ">newfile.txt") or print "can't open newfile.txt because $!";
#might give you a hint to what perl thought the problem was.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tpryorCommented:
have perl create the file, that way it could write to it.
0
 
jbirkAuthor Commented:
Changing the mod to 666 didn't help.  I'm going to check out ozo's suggestion.
And I also tried tpryor's suggestion before asking the question.  It won't create the file either??!???
0
 
jbirkAuthor Commented:
OK, I jumped the gun.  After playing using ozo's suggestion, I got the message 'Permission Denied'  So I though about it, and it seemed like b2pi had to be right, but the files had write permission.  It was the fact that it didn't even create files that tiped me off to the solution.  The directory needed write permission as well.  For some reason the system changed a couple weeks ago, and the permissions where affected somehow (because it DID work fine before).  But now with the directory AND file having write permission to everyone, it works again.

I'm not sure how to give the credit here.  You all provided clues to the solution.  Any suggestions?  Any way to split up points?

I really think they should change the system so that the asker of the question could assign points to the people writing the comments as they see fit after a satisfactory solution has been found (then splitting points would be easy! and people wouldn't accidentally answer questions instead of commenting).

Anyway, thank you all for your help!
0
 
b2piCommented:
Was it that you didn't have write rights to the _directory_ ?
0
 
jbirkAuthor Commented:
yes that's correct.  You sort of answered with that solution b2pi, but you weren't specific enough for me to realize that right away.  I just thought of the file itself, and forgot about the directory.

I guess if you answer the question again, I can give you the points, but a B for the grade, since it was the right solution, just not stated clearly enough.

But I'd like to give some points to the others as well, since helped me figure it out as well.
(how do I do that?)

Thanks for the help!
0
 
b2piCommented:
I'm relatively new on the system, and can't really tell you how to split the points.  Sorry.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now