Click to See Complete Forum and Search --> : perl writing to server problem


dmohtc
05-28-2005, 02:52 AM
Hi guys..I have a problem which i really dont know whats going on...wld b glad to hear any advice

I have a cgi script that writes to a text file on the server, everything seems to be working well except that the log file ie test.txt must be placed at top level,
ie if my home directory is /home/lookout/g2/huang21 the test.txt must be placed there

/home/lookout/g2/huang21/www/cgi-bin or
/home/lookout/g2/huang21/www/
or anywhere else simply wont work, which I have no idea why at all. I have checked all the file permissions and I dont think that is the problem.

Now I have moved off from my school server and i took up a new server which my files are placed at /var/www/cgi-bin & html at /var/www/html. I cld get the normal cgi files to work, but I could no longer write to file.



-------------------
#!/usr/local/bin/perl
# wdwrite
# this is the CGI that will take the # applet info and write it to a

file
#use strict;
open(OUT,'>/home/lookout/g2/huang21/test.txt') || die "cannot open file.";
print OUT "I cld print this fine";
while (<>) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;


*this wld work..but when i changed to
open(OUT,'>/home/lookout/g2/huang21/www/cgi-bin/test.txt') || die "cannot open file.";
print OUT "I cld print this fine";

it wont.
sigh...anyone?
thanks

Ultimater
05-29-2005, 10:32 AM
I think your new server is probably a UNIX server and your previous server was a WINDOWS server.
Try:

#!/usr/bin/perl -w
# provide the full path:
$fullFileLocation='http://www.blah.com/blah/blah2/test.txt'

open(OUT,'>'.$fullFileLocation) || die "cannot open file.";
print OUT "I cld print this fine";
while (<>) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;

dmohtc
05-29-2005, 03:57 PM
hmm...I tried that but it doesnt work as well, and I thought for open() we have to provide a linux path ie /var/www/html instead of an http path. Any other suggestions? thanks

Ultimater
05-29-2005, 04:03 PM
Sorry, forgot the semicolon :D :

$fullFileLocation='http://www.blah.com/blah/blah2/test.txt';

dmohtc
05-29-2005, 04:09 PM
yep I filled that in already, still doesnt..sigh..thanks

Ultimater
05-29-2005, 04:38 PM
Does your code even work this far? :

#!/usr/bin/perl -w
$fullFileLocation='http://www.blah.com/blah/blah2/test.txt';

print "Content-type: text/html\n\n";
if( open(OUT,'>'.$fullFileLocation) ){
print "exisits!";
}
else{
print "doesn't esist!";
}

dmohtc
05-29-2005, 05:37 PM
this works on my school server, which i could write the files by using
open(OUT,'>/home/lookout/g2/huang21/test.txt') || die "cannot open file.";

but I cant seem to store my file anywhere other than that, eg
/home/lookout/g2/huang21/www/test.txt
or /home/lookout/g2/huang21/www/cgi-bin
which is my internet directory.

my new servers giving me a real headache. cgi apparently works there,
http://loneliness.us/cgi-bin/test.cgi actually runs the script.
but when I download the script, rename it and upload it again it doesnt work anymore.
http://loneliness.us/cgi-bin/test2.cgi is the same file. and I cant your script to work there, it gives the internal 500 error.
My ftp is transferring cgi files using ascii mode, so that doesnt seem to be the problem. argh.

any advice? thanks

Ultimater
05-29-2005, 05:58 PM
You need to set the file permissions to 755 :)
When your files are in the ftp you need to right-click on them one at a time and set their permissions via checkboxes.

You should recieve 3 rows and 3 cols of checkboxes in a dialog box.

The Owner Read, Write and execute checkboxes should be all checked.
The Group Read and execute checkboxes should be checked.
The All users Read and execute checkboxes should be checked.
The following 2 checkboxes should be unchecked:
Group Write and All Users Write.

If you're dialog is in the same format as mine, you'd check 'em like this:
xxx
x_x
x_x

Ultimater
05-29-2005, 06:03 PM
Also, alot of times one server wants a perceeding forward-slash while others don't.
instead of:
'/home/lookout/g2/huang21/test.txt'
try:
'home/lookout/g2/huang21/test.txt'

dmohtc
05-29-2005, 06:25 PM
hmm....I set them all to 777, thought 777 would include 755 and more, but it apparently doesnt. Thanks! that fixed the cgi part and it displays the doesnt exist now.

I tried both the forward slashes and without, still not working. The text.txt log file has to be 777? or 755.

Any other suggestions? thanks a mil

dmohtc
05-29-2005, 06:39 PM
hmm..I found that I could store the file in /tmp/test.txt too.
I chked /tmp has permissions of 777.
I tried to change /home/dmohtc to 777 too but it wont work.

Is there any security issues if i store it in /tmp?

Ultimater
05-29-2005, 07:02 PM
For your TXT file, you can basicly give it any permission ya want :)
I'd set it to:
Owner: checked (all three)
Group: unchecked (all three)
All users: unchecked (all three)

However your CGI file isn't as flexable with regards to the permissions because it needs to be executed rather than read.
If you decided to store your information inside of a CGI file rather than a TXT file, you can give that CGI file basicly any permission-combo you want :)
I'd set it to:
Owner: checked (all three)
Group: unchecked (all three)
All users: unchecked (all three)
(just like the text file)

dmohtc
05-29-2005, 11:09 PM
ic...guess ill have to store it in /tmp/test.txt till I figure out why i cant store it anywhere else, anyone knows if theres an issue if I store it in /tmp directory..thanks

Jeff Mott
05-30-2005, 09:48 PM
Are you absolutely certain you have the path correct? Can you, for instance, write to a file with a relative path?

open(OUT, '>file.txt') or die $!;

Ultimater
# provide the full path:
$fullFileLocation='http://www.blah.com/blah/blah2/test.txt'Why are you trying to pass an internet address to the open function???